@@ -628,8 +628,8 @@ class Http2Incoming extends Readable {
628628 super ( initHttp2IncomingOptions ( options ) ) ;
629629 if ( ! ( stream instanceof Http2Stream ) )
630630 throw new TypeError ( 'stream argument must be an Http2Stream instance' ) ;
631- if ( ! ( headers instanceof Map ) )
632- throw new TypeError ( 'headers argument must be a Map ' ) ;
631+ if ( typeof headers !== 'object' )
632+ throw new TypeError ( 'headers argument must be an object ' ) ;
633633 this [ kStream ] = stream ;
634634 this [ kHeaders ] = headers ;
635635 this [ kFinished ] = false ;
@@ -679,19 +679,19 @@ class Http2ServerRequest extends Http2Incoming {
679679 }
680680
681681 get method ( ) {
682- return this . headers . get ( constants . HTTP2_HEADER_METHOD ) ;
682+ return this . headers [ constants . HTTP2_HEADER_METHOD ] ;
683683 }
684684
685685 get authority ( ) {
686- return this . headers . get ( constants . HTTP2_HEADER_AUTHORITY ) ;
686+ return this . headers [ constants . HTTP2_HEADER_AUTHORITY ] ;
687687 }
688688
689689 get scheme ( ) {
690- return this . headers . get ( constants . HTTP2_HEADER_SCHEME ) ;
690+ return this . headers [ constants . HTTP2_HEADER_SCHEME ] ;
691691 }
692692
693693 get url ( ) {
694- return this . headers . get ( constants . HTTP2_HEADER_PATH ) ;
694+ return this . headers [ constants . HTTP2_HEADER_PATH ] ;
695695 }
696696}
697697
@@ -762,18 +762,20 @@ class Http2Outgoing extends Writable {
762762 }
763763
764764 addHeaders ( headers ) {
765- if ( ! headers ) return ;
766- const keys = Object . keys ( headers ) ;
767- for ( const key of keys )
768- this . setHeader ( key , headers [ key ] ) ;
765+ var keys ;
766+ if ( headers ) {
767+ keys = Object . keys ( headers ) ;
768+ for ( var i = 0 ; i < keys . length ; i ++ )
769+ this . setHeader ( keys [ i ] , headers [ keys [ i ] ] ) ;
770+ }
769771 return this ;
770772 }
771773
772774 addTrailers ( headers ) {
773775 if ( ! headers ) return ;
774776 const keys = Object . keys ( headers ) ;
775- for ( const key of keys )
776- this . setTrailer ( key , headers [ key ] ) ;
777+ for ( var i = 0 ; i < keys . length ; i ++ )
778+ this . setTrailer ( keys [ i ] , headers [ keys [ i ] ] ) ;
777779 return this ;
778780 }
779781
@@ -920,44 +922,44 @@ class Http2PushResponse extends EventEmitter {
920922 constructor ( response ) {
921923 super ( ) ;
922924 this [ kResponse ] = response ;
923- this [ kHeaders ] = new Map ( ) ;
924- this . headers . set ( constants . HTTP2_HEADER_METHOD , 'GET' ) ;
925- this . headers . set ( constants . HTTP2_HEADER_AUTHORITY ,
926- response . stream [ kRequest ] . authority ) ;
927- this . headers . set ( constants . HTTP2_HEADER_SCHEME ,
928- response . stream [ kRequest ] . scheme ) ;
925+ this [ kHeaders ] = Object . create ( null ) ;
926+ this . headers [ constants . HTTP2_HEADER_METHOD ] = 'GET' ;
927+ this . headers [ constants . HTTP2_HEADER_AUTHORITY ] =
928+ response . stream [ kRequest ] . authority ;
929+ this . headers [ constants . HTTP2_HEADER_SCHEME ] =
930+ response . stream [ kRequest ] . scheme ;
929931 }
930932
931933 get path ( ) {
932- return this . headers . get ( constants . HTTP2_HEADER_PATH ) ;
934+ return this . headers [ constants . HTTP2_HEADER_PATH ] ;
933935 }
934936
935937 set path ( val ) {
936- this . headers . set ( constants . HTTP2_HEADER_PATH , String ( val ) ) ;
938+ this . headers [ constants . HTTP2_HEADER_PATH ] = String ( val ) ;
937939 }
938940
939941 get method ( ) {
940- return this . headers . get ( constants . HTTP2_HEADER_METHOD ) ;
942+ return this . headers [ constants . HTTP2_HEADER_METHOD ] ;
941943 }
942944
943945 set method ( val ) {
944- this . headers . set ( constants . HTTP2_HEADER_METHOD , String ( val ) ) ;
946+ this . headers [ constants . HTTP2_HEADER_METHOD ] = String ( val ) ;
945947 }
946948
947949 get authority ( ) {
948- return this . headers . get ( constants . HTTP2_HEADER_AUTHORITY ) ;
950+ return this . headers [ constants . HTTP2_HEADER_AUTHORITY ] ;
949951 }
950952
951953 set authority ( val ) {
952- this . headers . set ( constants . HTTP2_HEADER_AUTHORITY , String ( val ) ) ;
954+ this . headers [ constants . HTTP2_HEADER_AUTHORITY ] = String ( val ) ;
953955 }
954956
955957 get scheme ( ) {
956- return this . headers . get ( constants . HTTP2_HEADER_SCHEME ) ;
958+ return this . headers [ constants . HTTP2_HEADER_SCHEME ] ;
957959 }
958960
959961 set scheme ( val ) {
960- this . headers . set ( constants . HTTP2_HEADER_SCHEME , String ( val ) ) ;
962+ this . headers [ constants . HTTP2_HEADER_SCHEME ] = String ( val ) ;
961963 }
962964
963965 get headers ( ) {
@@ -1014,29 +1016,30 @@ function isIllegalConnectionSpecificHeader(name, value) {
10141016 }
10151017}
10161018
1017- // Converts a ES6 map into an http2.Http2Headers object.
1019+ // Converts an object into an http2.Http2Headers object.
10181020// The Http2Headers object maintains an internal array
10191021// of nghttp2_nv objects that contain a copy of the
10201022// header value pairs as an std::vector. To avoid
10211023// that vector having to copy and reallocate, we count
10221024// the number of expected items up front (it's less
10231025// expensive to count than it is to reallocate).
10241026function mapToHeaders ( map ) {
1025- var size = map . size ;
1026- for ( const v of map ) {
1027- if ( Array . isArray ( v [ 1 ] ) ) {
1028- size += v [ 1 ] . length - 1 ;
1027+ const keys = Object . keys ( map )
1028+ var size = keys . length ;
1029+ for ( var i = 0 ; i < keys . length ; i ++ ) {
1030+ if ( Array . isArray ( keys [ i ] ) ) {
1031+ size += keys [ i ] . length - 1 ;
10291032 }
10301033 }
10311034 const ret = new http2 . Http2Headers ( size ) ;
1032- if ( ! ( map instanceof Map ) )
1033- return ret ;
1034- for ( const v of map ) {
1035- const key = String ( v [ 0 ] ) ;
1036- const value = v [ 1 ] ;
1035+
1036+ for ( i = 0 ; i < keys . length ; i ++ ) {
1037+ const key = keys [ i ]
1038+ const value = map [ key ] ;
10371039 if ( Array . isArray ( value ) && value . length > 0 ) {
1038- for ( const item of value )
1039- ret . add ( key , String ( item ) ) ;
1040+ for ( var k = 0 ; k < value . length ; k ++ ) {
1041+ ret . add ( key , String ( value [ k ] ) ) ;
1042+ }
10401043 } else {
10411044 ret . add ( key , String ( value ) ) ;
10421045 }
@@ -1165,12 +1168,12 @@ function sessionOnHeaderComplete(stream, flags, headers, category) {
11651168 if ( finished )
11661169 request [ kFinished ] = true ;
11671170
1168- if ( headers . has ( ' expect' ) ) {
1171+ if ( headers . expect ) {
11691172 // If there is an expect header that contains 100-continue,
11701173 // and the server has a listener for the checkContinue event,
11711174 // emit the checkContinue event instead of the request event.
11721175 // This behavior matches the current http/1 API.
1173- if ( / ^ 1 0 0 - c o n t i n u e $ / i. test ( headers . get ( ' expect' ) ) ) {
1176+ if ( / ^ 1 0 0 - c o n t i n u e $ / i. test ( headers . expect ) ) {
11741177 if ( server . listenerCount ( 'checkContinue' ) > 0 ) {
11751178 request [ kInFlight ] = true ;
11761179 server . emit ( 'checkContinue' , request , response ) ;
@@ -1552,45 +1555,44 @@ class Http2ClientRequest extends Http2Outgoing {
15521555 var authority = options . hostname ;
15531556 if ( options . port )
15541557 authority += `:${ options . port } ` ;
1555- const headers = this [ kHeaders ] = new Map ( ) ;
1558+ const headers = this [ kHeaders ] = Object . create ( null ) ;
15561559
1557- headers . set ( constants . HTTP2_HEADER_SCHEME ,
1558- options . protocol . slice ( 0 , options . protocol . length - 1 ) ) ;
1559- headers . set ( constants . HTTP2_HEADER_METHOD , options . method ) ;
1560- headers . set ( constants . HTTP2_HEADER_AUTHORITY , authority ) ;
1561- headers . set ( constants . HTTP2_HEADER_PATH , options . pathname ) ;
1560+ headers [ constants . HTTP2_HEADER_SCHEME ] = options . protocol . slice ( 0 , options . protocol . length - 1 ) ;
1561+ headers [ constants . HTTP2_HEADER_METHOD ] = options . method ;
1562+ headers [ constants . HTTP2_HEADER_AUTHORITY ] = authority ;
1563+ headers [ constants . HTTP2_HEADER_PATH ] = options . pathname ;
15621564
15631565 if ( typeof callback === 'function' )
15641566 this . once ( 'response' , callback ) ;
15651567 }
15661568
15671569 setHeader ( name , value ) {
15681570 name = String ( name ) . toLowerCase ( ) . trim ( ) ;
1569- if ( this [ kHeaders ] . has ( name ) ) {
1570- const existing = this [ kHeaders ] . get ( name ) ;
1571+ const existing = this [ kHeaders ] [ name ] ;
1572+ if ( existing ) {
15711573 if ( Array . isArray ( existing ) ) {
15721574 existing . push ( String ( value ) ) ;
15731575 } else {
1574- this [ kHeaders ] . set ( name , [ existing , value ] ) ;
1576+ this [ kHeaders ] [ name ] = [ existing , value ] ;
15751577 }
15761578 } else {
1577- this [ kHeaders ] . set ( name , value ) ;
1579+ this [ kHeaders ] [ name ] = value ;
15781580 }
15791581 }
15801582
15811583 setTrailer ( name , value ) {
15821584 if ( ! this [ kTrailers ] )
1583- this [ kTrailers ] = new Map ( ) ;
1585+ this [ kTrailers ] = Object . create ( null ) ;
15841586 name = String ( name ) . toLowerCase ( ) . trim ( ) ;
1585- if ( this [ kTrailers ] . has ( name ) ) {
1586- const existing = this [ kTrailers ] . get ( name ) ;
1587+ const existing = this [ kTrailers ] [ name ] ;
1588+ if ( existing ) {
15871589 if ( Array . isArray ( existing ) ) {
15881590 existing . push ( String ( value ) ) ;
15891591 } else {
1590- this [ kTrailers ] . set ( name , [ existing , value ] ) ;
1592+ this [ kTrailers ] [ name ] = [ existing , value ] ;
15911593 }
15921594 } else {
1593- this [ kTrailers ] . set ( name , value ) ;
1595+ this [ kTrailers ] [ name ] = value ;
15941596 }
15951597 }
15961598
@@ -1613,13 +1615,13 @@ class Http2ClientRequest extends Http2Outgoing {
16131615
16141616function addTrailers ( ) {
16151617 const request = this [ kRequest ] ;
1616- if ( request [ kTrailers ] instanceof Map ) {
1617- for ( const v of request [ kTrailers ] ) {
1618- const key = String ( v [ 0 ] ) ;
1619- const value = v [ 1 ] ;
1618+ if ( request [ kTrailers ] ) {
1619+ // key is coerced on a string on set
1620+ for ( var key in request [ kTrailers ] ) {
1621+ const value = request [ kTrailers ] [ key ] ;
16201622 if ( Array . isArray ( value ) && value . length > 0 ) {
1621- for ( const item of value )
1622- this . addTrailer ( key , String ( item ) ) ;
1623+ for ( var i = 0 ; i < value . length ; i ++ )
1624+ this . addTrailer ( key , String ( value [ i ] ) ) ;
16231625 } else {
16241626 this . addTrailer ( key , String ( value ) ) ;
16251627 }
@@ -1633,7 +1635,7 @@ class Http2ClientResponse extends Http2Incoming {
16331635 }
16341636
16351637 get status ( ) {
1636- return this . headers . get ( constants . HTTP2_HEADER_STATUS ) | 0 ;
1638+ return this . headers [ constants . HTTP2_HEADER_STATUS ] | 0 ;
16371639 }
16381640}
16391641
0 commit comments