File tree Expand file tree Collapse file tree 3 files changed +30
-14
lines changed Expand file tree Collapse file tree 3 files changed +30
-14
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @remix-run/web-fetch " : patch
3+ ---
4+
5+ Support HTTP2 pseudo-headers like ` :authority ` , ` :method ` , etc.
Original file line number Diff line number Diff line change @@ -8,21 +8,19 @@ import {types} from 'util';
88import http from 'http' ;
99import { isIterable } from './utils/is.js'
1010
11- const validators = /** @type {{validateHeaderName?:(name:string) => any, validateHeaderValue?:(name:string, value:string) => any} } */
12- ( http )
11+ /** @type {{validateHeaderValue?:(name:string, value:string) => any} } */
12+ const validators = ( http )
1313
14- const validateHeaderName = typeof validators . validateHeaderName === 'function' ?
15- validators . validateHeaderName :
16- /**
17- * @param {string } name
18- */
19- name => {
20- if ( ! / ^ [ \^ ` \- \w ! # $ % & ' * + . | ~ ] + $ / . test ( name ) ) {
21- const err = new TypeError ( `Header name must be a valid HTTP token [${ name } ]` ) ;
22- Object . defineProperty ( err , 'code' , { value : 'ERR_INVALID_HTTP_TOKEN' } ) ;
23- throw err ;
24- }
25- } ;
14+ /**
15+ * @param {string } name
16+ */
17+ const validateHeaderName = name => {
18+ if ( ! / ^ [ \^ ` \- \w ! # $ % & ' * + . | ~ : ] + $ / . test ( name ) ) {
19+ const err = new TypeError ( `Header name must be a valid HTTP token [${ name } ]` ) ;
20+ Object . defineProperty ( err , 'code' , { value : 'ERR_INVALID_HTTP_TOKEN' } ) ;
21+ throw err ;
22+ }
23+ } ;
2624
2725const validateHeaderValue = typeof validators . validateHeaderValue === 'function' ?
2826 validators . validateHeaderValue :
Original file line number Diff line number Diff line change @@ -216,6 +216,19 @@ describe('Headers', () => {
216216 expect ( ( ) => headers . append ( '' , 'ok' ) ) . to . throw ( TypeError ) ;
217217 } ) ;
218218
219+ it ( 'should allow HTTP2 pseudo-headers' , ( ) => {
220+ let headers = new Headers ( { ':authority' : 'something' } ) ;
221+ headers . append ( ":method" , "something else" )
222+
223+ const result = [ ] ;
224+ for ( const pair of headers ) {
225+ result . push ( pair ) ;
226+ }
227+
228+ expect ( result ) . to . deep . equal ( [ [ ':authority' , 'something' ] , [ ':method' , 'something else' ] ] ) ;
229+
230+ } )
231+
219232 it ( 'should ignore unsupported attributes while reading headers' , ( ) => {
220233 const FakeHeader = function ( ) { } ;
221234 // Prototypes are currently ignored
You can’t perform that action at this time.
0 commit comments