@@ -48,9 +48,16 @@ const {
4848
4949 HTTP2_METHOD_DELETE ,
5050 HTTP2_METHOD_GET ,
51- HTTP2_METHOD_HEAD
51+ HTTP2_METHOD_HEAD ,
52+
53+ NGHTTP2_NV_FLAG_NONE ,
54+ NGHTTP2_NV_FLAG_NO_INDEX
5255} = binding . constants ;
5356
57+ const HEADER_DEFAULT = String . fromCharCode ( NGHTTP2_NV_FLAG_NONE ) ;
58+ const HEADER_NO_STORE = String . fromCharCode ( NGHTTP2_NV_FLAG_NO_INDEX ) ;
59+ const noStore = Symbol ( 'http2.noStore' ) ;
60+
5461// This set is defined strictly by the HTTP/2 specification. Only
5562// :-prefixed headers defined by that specification may be added to
5663// this set.
@@ -374,11 +381,12 @@ function assertValidPseudoHeaderTrailer(key) {
374381}
375382
376383function mapToHeaders ( map ,
377- assertValuePseudoHeader = assertValidPseudoHeader ) {
384+ assertValuePseudoHeader = assertValidPseudoHeader ,
385+ flag = HEADER_DEFAULT ,
386+ singles = new Set ( ) ) {
378387 let ret = '' ;
379388 let count = 0 ;
380389 const keys = Object . keys ( map ) ;
381- const singles = new Set ( ) ;
382390 for ( var i = 0 ; i < keys . length ; i ++ ) {
383391 let key = keys [ i ] ;
384392 let value = map [ key ] ;
@@ -403,7 +411,9 @@ function mapToHeaders(map,
403411 const err = assertValuePseudoHeader ( key ) ;
404412 if ( err !== undefined )
405413 return err ;
406- ret = `${ key } \0${ String ( value ) } \0${ ret } ` ;
414+ // The first byte is always 0, passing NGHTTP2_NV_FLAG_NO_INDEX
415+ // does not make sense for pseudo-headers.
416+ ret = `\0${ key } \0${ String ( value ) } \0${ ret } ` ;
407417 count ++ ;
408418 } else {
409419 if ( kSingleValueHeaders . has ( key ) ) {
@@ -417,17 +427,30 @@ function mapToHeaders(map,
417427 if ( isArray ) {
418428 for ( var k = 0 ; k < value . length ; k ++ ) {
419429 val = String ( value [ k ] ) ;
420- ret += `${ key } \0${ val } \0` ;
430+ ret += `${ flag } ${ key } \0${ val } \0` ;
421431 }
422432 count += value . length ;
423433 } else {
424434 val = String ( value ) ;
425- ret += `${ key } \0${ val } \0` ;
435+ ret += `${ flag } ${ key } \0${ val } \0` ;
426436 count ++ ;
427437 }
428438 }
429439 }
430440
441+ const noStoreMap = map [ noStore ] ;
442+ if ( noStoreMap !== undefined ) {
443+ const info = mapToHeaders (
444+ noStoreMap ,
445+ ( key ) => new errors . Error ( 'ERR_HTTP2_PSEUDOHEADER_INVALID_FLAGS' , key ) ,
446+ HEADER_NO_STORE ,
447+ singles ) ;
448+ if ( ! Array . isArray ( info ) )
449+ return info ;
450+ ret += info [ 0 ] ;
451+ count += info [ 1 ] ;
452+ }
453+
431454 return [ ret , count ] ;
432455}
433456
@@ -510,6 +533,7 @@ module.exports = {
510533 isPayloadMeaningless,
511534 mapToHeaders,
512535 NghttpError,
536+ noStore,
513537 toHeaderObject,
514538 updateOptionsBuffer,
515539 updateSettingsBuffer
0 commit comments