@@ -365,8 +365,7 @@ added: v8.4.0
365
365
* ` stream ` {Http2Stream} A reference to the stream
366
366
* ` headers ` {HTTP/2 Headers Object} An object describing the headers
367
367
* ` flags ` {number} The associated numeric flags
368
- * ` rawHeaders ` {Array} An array containing the raw header names followed by
369
- their respective values.
368
+ * ` rawHeaders ` {HTTP/2 Raw Headers} An array containing the raw headers
370
369
371
370
The ` 'stream' ` event is emitted when a new ` Http2Stream ` is created.
372
371
@@ -1087,7 +1086,7 @@ changes:
1087
1086
description: Allow passing headers in raw array format.
1088
1087
-->
1089
1088
1090
- * ` headers ` {HTTP/2 Headers Object|Array }
1089
+ * ` headers ` {HTTP/2 Headers Object|HTTP/2 Raw Headers }
1091
1090
1092
1091
* ` options ` {Object}
1093
1092
* ` endStream ` {boolean} ` true ` if the ` Http2Stream ` _ writable_ side should
@@ -1675,11 +1674,12 @@ added: v8.4.0
1675
1674
1676
1675
* ` headers ` {HTTP/2 Headers Object}
1677
1676
* ` flags ` {number}
1677
+ * ` rawHeaders ` {HTTP/2 Raw Headers}
1678
1678
1679
1679
The ` 'headers' ` event is emitted when an additional block of headers is received
1680
1680
for a stream, such as when a block of ` 1xx ` informational headers is received.
1681
- The listener callback is passed the [ HTTP/2 Headers Object] [ ] and flags
1682
- associated with the headers.
1681
+ The listener callback is passed the [ HTTP/2 Headers Object] [ ] , flags associated
1682
+ with the headers, and the headers in raw format (see [ HTTP/2 Raw Headers ] [ ] ) .
1683
1683
1684
1684
``` js
1685
1685
stream .on (' headers' , (headers , flags ) => {
@@ -1714,11 +1714,13 @@ added: v8.4.0
1714
1714
1715
1715
* ` headers ` {HTTP/2 Headers Object}
1716
1716
* ` flags ` {number}
1717
+ * ` rawHeaders ` {HTTP/2 Raw Headers}
1717
1718
1718
1719
The ` 'response' ` event is emitted when a response ` HEADERS ` frame has been
1719
1720
received for this stream from the connected HTTP/2 server. The listener is
1720
- invoked with two arguments: an ` Object ` containing the received
1721
- [ HTTP/2 Headers Object] [ ] , and flags associated with the headers.
1721
+ invoked with three arguments: an ` Object ` containing the received
1722
+ [ HTTP/2 Headers Object] [ ] , flags associated with the headers, and the headers
1723
+ in raw format (see [ HTTP/2 Raw Headers] [ ] ).
1722
1724
1723
1725
``` mjs
1724
1726
import { connect } from ' node:http2' ;
@@ -1866,7 +1868,7 @@ changes:
1866
1868
description: Allow explicitly setting date headers.
1867
1869
-->
1868
1870
1869
- * ` headers ` {HTTP/2 Headers Object|Array }
1871
+ * ` headers ` {HTTP/2 Headers Object|HTTP/2 Raw Headers }
1870
1872
* ` options ` {Object}
1871
1873
* ` endStream ` {boolean} Set to ` true ` to indicate that the response will not
1872
1874
include payload data.
@@ -2350,8 +2352,7 @@ added: v8.4.0
2350
2352
* ` stream ` {Http2Stream} A reference to the stream
2351
2353
* ` headers ` {HTTP/2 Headers Object} An object describing the headers
2352
2354
* ` flags ` {number} The associated numeric flags
2353
- * ` rawHeaders ` {Array} An array containing the raw header names followed by
2354
- their respective values.
2355
+ * ` rawHeaders ` {HTTP/2 Raw Headers} An array containing the raw headers
2355
2356
2356
2357
The ` 'stream' ` event is emitted when a ` 'stream' ` event has been emitted by
2357
2358
an ` Http2Session ` associated with the server.
@@ -2606,8 +2607,7 @@ added: v8.4.0
2606
2607
* ` stream ` {Http2Stream} A reference to the stream
2607
2608
* ` headers ` {HTTP/2 Headers Object} An object describing the headers
2608
2609
* ` flags ` {number} The associated numeric flags
2609
- * ` rawHeaders ` {Array} An array containing the raw header names followed by
2610
- their respective values.
2610
+ * ` rawHeaders ` {HTTP/2 Raw Headers} An array containing the raw headers
2611
2611
2612
2612
The ` 'stream' ` event is emitted when a ` 'stream' ` event has been emitted by
2613
2613
an ` Http2Session ` associated with the server.
@@ -3450,6 +3450,32 @@ server.on('stream', (stream, headers) => {
3450
3450
});
3451
3451
```
3452
3452
3453
+ #### Raw headers
3454
+
3455
+ In some APIs, in addition to object format, headers can also be passed or
3456
+ accessed as a raw flat array, preserving details of ordering and
3457
+ duplicate keys to match the raw transmission format.
3458
+
3459
+ In this format the keys and values are in the same list. It is _ not_ a
3460
+ list of tuples. So, the even-numbered offsets are key values, and the
3461
+ odd-numbered offsets are the associated values. Duplicate headers are
3462
+ not merged and so each key-value pair will appear separately.
3463
+
3464
+ This can be useful for cases such as proxies, where existing headers
3465
+ should be exactly forwarded as received, or as a performance
3466
+ optimization when the headers are already available in raw format.
3467
+
3468
+ ``` js
3469
+ const rawHeaders = [
3470
+ ' :status' ,
3471
+ ' 404' ,
3472
+ ' content-type' ,
3473
+ ' text/plain' ,
3474
+ ];
3475
+
3476
+ stream .respond (rawHeaders);
3477
+ ```
3478
+
3453
3479
#### Sensitive headers
3454
3480
3455
3481
HTTP2 headers can be marked as sensitive, which means that the HTTP/2
@@ -3476,6 +3502,10 @@ this flag is set automatically.
3476
3502
This property is also set for received headers. It will contain the names of
3477
3503
all headers marked as sensitive, including ones marked that way automatically.
3478
3504
3505
+ For raw headers, this should still be set as a property on the array, like
3506
+ ` rawHeadersArray[http2.sensitiveHeaders] = ['cookie'] ` , not as a separate key
3507
+ and value pair within the array itself.
3508
+
3479
3509
### Settings object
3480
3510
3481
3511
<!-- YAML
@@ -4072,16 +4102,10 @@ The request method as a string. Read-only. Examples: `'GET'`, `'DELETE'`.
4072
4102
added: v8.4.0
4073
4103
-->
4074
4104
4075
- * Type: {string \[ ] }
4105
+ * Type: {HTTP/2 Raw Headers }
4076
4106
4077
4107
The raw request/response headers list exactly as they were received.
4078
4108
4079
- The keys and values are in the same list. It is _ not_ a
4080
- list of tuples. So, the even-numbered offsets are key values, and the
4081
- odd-numbered offsets are the associated values.
4082
-
4083
- Header names are not lowercased, and duplicates are not merged.
4084
-
4085
4109
``` js
4086
4110
// Prints something like:
4087
4111
//
@@ -4762,7 +4786,7 @@ changes:
4762
4786
4763
4787
* ` statusCode ` {number}
4764
4788
* ` statusMessage ` {string}
4765
- * ` headers ` {Object|Array }
4789
+ * ` headers ` {HTTP/2 Headers Object|HTTP/2 Raw Headers }
4766
4790
* Returns: {http2.Http2ServerResponse}
4767
4791
4768
4792
Sends a response header to the request. The status code is a 3-digit HTTP
@@ -4906,6 +4930,7 @@ you need to implement any fall-back behavior yourself.
4906
4930
[ HTTP/1 ] : http.md
4907
4931
[ HTTP/2 ] : https://tools.ietf.org/html/rfc7540
4908
4932
[ HTTP/2 Headers Object ] : #headers-object
4933
+ [ HTTP/2 Raw Headers ] : #raw-headers
4909
4934
[ HTTP/2 Settings Object ] : #settings-object
4910
4935
[ HTTP/2 Unencrypted ] : https://http2.github.io/faq/#does-http2-require-encryption
4911
4936
[ HTTPS ] : https.md
0 commit comments