@@ -13,7 +13,9 @@ const kStream = Symbol('stream');
13
13
const kRequest = Symbol ( 'request' ) ;
14
14
const kResponse = Symbol ( 'response' ) ;
15
15
const kHeaders = Symbol ( 'headers' ) ;
16
+ const kRawHeaders = Symbol ( 'rawHeaders' ) ;
16
17
const kTrailers = Symbol ( 'trailers' ) ;
18
+ const kRawTrailers = Symbol ( 'rawTrailers' ) ;
17
19
18
20
let statusMessageWarned = false ;
19
21
@@ -45,12 +47,28 @@ function isPseudoHeader(name) {
45
47
}
46
48
}
47
49
50
+ function statusMessageWarn ( ) {
51
+ if ( statusMessageWarned === false ) {
52
+ process . emitWarning (
53
+ 'Status message is not supported by HTTP/2 (RFC7540 8.1.2.4)' ,
54
+ 'UnsupportedWarning'
55
+ ) ;
56
+ statusMessageWarned = true ;
57
+ }
58
+ }
59
+
48
60
function onStreamData ( chunk ) {
49
61
const request = this [ kRequest ] ;
50
62
if ( ! request . push ( chunk ) )
51
63
this . pause ( ) ;
52
64
}
53
65
66
+ function onStreamTrailers ( trailers , flags , rawTrailers ) {
67
+ const request = this [ kRequest ] ;
68
+ Object . assign ( request [ kTrailers ] , trailers ) ;
69
+ request [ kRawTrailers ] . push ( ...rawTrailers ) ;
70
+ }
71
+
54
72
function onStreamEnd ( ) {
55
73
// Cause the request stream to end as well.
56
74
const request = this [ kRequest ] ;
@@ -106,20 +124,24 @@ function onAborted(hadError, code) {
106
124
}
107
125
108
126
class Http2ServerRequest extends Readable {
109
- constructor ( stream , headers , options ) {
127
+ constructor ( stream , headers , options , rawHeaders ) {
110
128
super ( options ) ;
111
129
this [ kState ] = {
112
130
statusCode : null ,
113
131
closed : false ,
114
132
closedCode : constants . NGHTTP2_NO_ERROR
115
133
} ;
116
134
this [ kHeaders ] = headers ;
135
+ this [ kRawHeaders ] = rawHeaders ;
136
+ this [ kTrailers ] = { } ;
137
+ this [ kRawTrailers ] = [ ] ;
117
138
this [ kStream ] = stream ;
118
139
stream [ kRequest ] = this ;
119
140
120
141
// Pause the stream..
121
142
stream . pause ( ) ;
122
143
stream . on ( 'data' , onStreamData ) ;
144
+ stream . on ( 'trailers' , onStreamTrailers ) ;
123
145
stream . on ( 'end' , onStreamEnd ) ;
124
146
stream . on ( 'error' , onStreamError ) ;
125
147
stream . on ( 'close' , onStreamClosedRequest ) ;
@@ -155,18 +177,17 @@ class Http2ServerRequest extends Readable {
155
177
}
156
178
157
179
get rawHeaders ( ) {
158
- const headers = this [ kHeaders ] ;
159
- if ( headers === undefined )
160
- return [ ] ;
161
- const tuples = Object . entries ( headers ) ;
162
- const flattened = Array . prototype . concat . apply ( [ ] , tuples ) ;
163
- return flattened . map ( String ) ;
180
+ return this [ kRawHeaders ] ;
164
181
}
165
182
166
183
get trailers ( ) {
167
184
return this [ kTrailers ] ;
168
185
}
169
186
187
+ get rawTrailers ( ) {
188
+ return this [ kRawTrailers ] ;
189
+ }
190
+
170
191
get httpVersionMajor ( ) {
171
192
return 2 ;
172
193
}
@@ -382,30 +403,25 @@ class Http2ServerResponse extends Stream {
382
403
}
383
404
384
405
get statusMessage ( ) {
385
- if ( statusMessageWarned === false ) {
386
- process . emitWarning (
387
- 'Status message is not supported by HTTP/2 (RFC7540 8.1.2.4)' ,
388
- 'UnsupportedWarning'
389
- ) ;
390
- statusMessageWarned = true ;
391
- }
406
+ statusMessageWarn ( ) ;
392
407
393
408
return '' ;
394
409
}
395
410
411
+ set statusMessage ( msg ) {
412
+ statusMessageWarn ( ) ;
413
+ }
414
+
396
415
flushHeaders ( ) {
397
416
if ( this [ kStream ] . headersSent === false )
398
417
this [ kBeginSend ] ( ) ;
399
418
}
400
419
401
420
writeHead ( statusCode , statusMessage , headers ) {
402
- if ( typeof statusMessage === 'string' && statusMessageWarned === false ) {
403
- process . emitWarning (
404
- 'Status message is not supported by HTTP/2 (RFC7540 8.1.2.4)' ,
405
- 'UnsupportedWarning'
406
- ) ;
407
- statusMessageWarned = true ;
421
+ if ( typeof statusMessage === 'string' ) {
422
+ statusMessageWarn ( ) ;
408
423
}
424
+
409
425
if ( headers === undefined && typeof statusMessage === 'object' ) {
410
426
headers = statusMessage ;
411
427
}
@@ -542,9 +558,10 @@ class Http2ServerResponse extends Stream {
542
558
}
543
559
}
544
560
545
- function onServerStream ( stream , headers , flags ) {
561
+ function onServerStream ( stream , headers , flags , rawHeaders ) {
546
562
const server = this ;
547
- const request = new Http2ServerRequest ( stream , headers ) ;
563
+ const request = new Http2ServerRequest ( stream , headers , undefined ,
564
+ rawHeaders ) ;
548
565
const response = new Http2ServerResponse ( stream ) ;
549
566
550
567
// Check for the CONNECT method
0 commit comments