@@ -346,6 +346,9 @@ added: REPLACEME
346
346
* ` weight ` {number} Specifies the relative dependency of a stream in relation
347
347
to other streams with the same ` parent ` . The value is a number between ` 1 `
348
348
and ` 256 ` (inclusive).
349
+ * ` getTrailers ` {Function} Callback function invoked to collect trailer
350
+ headers.
351
+
349
352
* Returns: {ClientHttp2Stream}
350
353
351
354
For HTTP/2 Client ` Http2Session ` instances only, the ` http2session.request() `
@@ -371,6 +374,16 @@ req.on('response', (headers) => {
371
374
});
372
375
```
373
376
377
+ When set, the ` options.getTrailers() ` function is called immediately after
378
+ queuing the last chunk of payload data to be sent. The callback is passed a
379
+ single object (with a ` null ` prototype) that the listener may used to specify
380
+ the trailing header fields to send to the peer.
381
+
382
+ * Note* : The HTTP/1 specification forbids trailers from containing HTTP/2
383
+ "pseudo-header" fields (e.g. ` ':method' ` , ` ':path' ` , etc). An ` 'error' ` event
384
+ will be emitted if the ` getTrailers ` callback attempts to set such header
385
+ fields.
386
+
374
387
#### http2session.rstStream(stream, code)
375
388
<!-- YAML
376
389
added: REPLACEME
@@ -617,27 +630,6 @@ added: REPLACEME
617
630
The ` 'error' ` event is emitted when an error occurs during the processing of
618
631
an ` Http2Stream ` .
619
632
620
- #### Event: 'fetchTrailers'
621
- <!-- YAML
622
- added: REPLACEME
623
- -->
624
-
625
- The ` 'fetchTrailers' ` event is emitted by the ` Http2Stream ` immediately after
626
- queuing the last chunk of payload data to be sent. The listener callback is
627
- passed a single object (with a ` null ` prototype) that the listener may used
628
- to specify the trailing header fields to send to the peer.
629
-
630
- ``` js
631
- stream .on (' fetchTrailers' , (trailers ) => {
632
- trailers[' ABC' ] = ' some value to send' ;
633
- });
634
- ```
635
-
636
- * Note* : The HTTP/1 specification forbids trailers from containing HTTP/2
637
- "pseudo-header" fields (e.g. ` ':status' ` , ` ':path' ` , etc). An ` 'error' ` event
638
- will be emitted if the ` 'fetchTrailers' ` event handler attempts to set such
639
- header fields.
640
-
641
633
#### Event: 'frameError'
642
634
<!-- YAML
643
635
added: REPLACEME
@@ -991,6 +983,8 @@ added: REPLACEME
991
983
* ` options ` {Object}
992
984
* ` endStream ` {boolean} Set to ` true ` to indicate that the response will not
993
985
include payload data.
986
+ * ` getTrailers ` {function} Callback function invoked to collect trailer
987
+ headers.
994
988
* Returns: {undefined}
995
989
996
990
``` js
@@ -1002,6 +996,29 @@ server.on('stream', (stream) => {
1002
996
});
1003
997
```
1004
998
999
+ When set, the ` options.getTrailers() ` function is called immediately after
1000
+ queuing the last chunk of payload data to be sent. The callback is passed a
1001
+ single object (with a ` null ` prototype) that the listener may used to specify
1002
+ the trailing header fields to send to the peer.
1003
+
1004
+ ``` js
1005
+ const http2 = require (' http2' );
1006
+ const server = http2 .createServer ();
1007
+ server .on (' stream' , (stream ) => {
1008
+ stream .respond ({ ' :status' : 200 }, {
1009
+ getTrailers (trailers ) {
1010
+ trailers[' ABC' ] = ' some value to send' ;
1011
+ }
1012
+ });
1013
+ stream .end (' some data' );
1014
+ });
1015
+ ```
1016
+
1017
+ * Note* : The HTTP/1 specification forbids trailers from containing HTTP/2
1018
+ "pseudo-header" fields (e.g. ` ':status' ` , ` ':path' ` , etc). An ` 'error' ` event
1019
+ will be emitted if the ` getTrailers ` callback attempts to set such header
1020
+ fields.
1021
+
1005
1022
#### http2stream.respondWithFD(fd[ , headers[ , options]] )
1006
1023
<!-- YAML
1007
1024
added: REPLACEME
@@ -1011,6 +1028,8 @@ added: REPLACEME
1011
1028
* ` headers ` {[ Headers Object] [ ] }
1012
1029
* ` options ` {Object}
1013
1030
* ` statCheck ` {Function}
1031
+ * ` getTrailers ` {Function} Callback function invoked to collect trailer
1032
+ headers.
1014
1033
* ` offset ` {number} The offset position at which to begin reading
1015
1034
* ` length ` {number} The amount of data from the fd to send
1016
1035
@@ -1020,8 +1039,7 @@ attempting to read data using the file descriptor, the `Http2Stream` will be
1020
1039
closed using an ` RST_STREAM ` frame using the standard ` INTERNAL_ERROR ` code.
1021
1040
1022
1041
When used, the ` Http2Stream ` object's Duplex interface will be closed
1023
- automatically. HTTP trailer fields cannot be sent. The ` 'fetchTrailers' ` event
1024
- will * not* be emitted.
1042
+ automatically.
1025
1043
1026
1044
``` js
1027
1045
const http2 = require (' http2' );
@@ -1052,6 +1070,39 @@ The `offset` and `length` options may be used to limit the response to a
1052
1070
specific range subset. This can be used, for instance, to support HTTP Range
1053
1071
requests.
1054
1072
1073
+ When set, the ` options.getTrailers() ` function is called immediately after
1074
+ queuing the last chunk of payload data to be sent. The callback is passed a
1075
+ single object (with a ` null ` prototype) that the listener may used to specify
1076
+ the trailing header fields to send to the peer.
1077
+
1078
+ ``` js
1079
+ const http2 = require (' http2' );
1080
+ const fs = require (' fs' );
1081
+
1082
+ const fd = fs .openSync (' /some/file' , ' r' );
1083
+
1084
+ const server = http2 .createServer ();
1085
+ server .on (' stream' , (stream ) => {
1086
+ const stat = fs .fstatSync (fd);
1087
+ const headers = {
1088
+ ' content-length' : stat .size ,
1089
+ ' last-modified' : stat .mtime .toUTCString (),
1090
+ ' content-type' : ' text/plain'
1091
+ };
1092
+ stream .respondWithFD (fd, headers, {
1093
+ getTrailers (trailers ) {
1094
+ trailers[' ABC' ] = ' some value to send' ;
1095
+ }
1096
+ });
1097
+ });
1098
+ server .on (' close' , () => fs .closeSync (fd));
1099
+ ```
1100
+
1101
+ * Note* : The HTTP/1 specification forbids trailers from containing HTTP/2
1102
+ "pseudo-header" fields (e.g. ` ':status' ` , ` ':path' ` , etc). An ` 'error' ` event
1103
+ will be emitted if the ` getTrailers ` callback attempts to set such header
1104
+ fields.
1105
+
1055
1106
#### http2stream.respondWithFile(path[ , headers[ , options]] )
1056
1107
<!-- YAML
1057
1108
added: REPLACEME
@@ -1061,15 +1112,16 @@ added: REPLACEME
1061
1112
* ` headers ` {[ Headers Object] [ ] }
1062
1113
* ` options ` {Object}
1063
1114
* ` statCheck ` {Function}
1115
+ * ` getTrailers ` {Function} Callback function invoked to collect trailer
1116
+ headers.
1064
1117
* ` offset ` {number} The offset position at which to begin reading
1065
1118
* ` length ` {number} The amount of data from the fd to send
1066
1119
1067
1120
Sends a regular file as the response. The ` path ` must specify a regular file
1068
1121
or an ` 'error' ` event will be emitted on the ` Http2Stream ` object.
1069
1122
1070
1123
When used, the ` Http2Stream ` object's Duplex interface will be closed
1071
- automatically. HTTP trailer fields cannot be sent. The ` 'fetchTrailers' ` event
1072
- will * not* be emitted.
1124
+ automatically.
1073
1125
1074
1126
The optional ` options.statCheck ` function may be specified to give user code
1075
1127
an opportunity to set additional content headers based on the ` fs.Stat ` details
@@ -1120,6 +1172,29 @@ The `offset` and `length` options may be used to limit the response to a
1120
1172
specific range subset. This can be used, for instance, to support HTTP Range
1121
1173
requests.
1122
1174
1175
+ When set, the ` options.getTrailers() ` function is called immediately after
1176
+ queuing the last chunk of payload data to be sent. The callback is passed a
1177
+ single object (with a ` null ` prototype) that the listener may used to specify
1178
+ the trailing header fields to send to the peer.
1179
+
1180
+ ``` js
1181
+ const http2 = require (' http2' );
1182
+ const server = http2 .createServer ();
1183
+ server .on (' stream' , (stream ) => {
1184
+ function getTrailers (trailers ) {
1185
+ trailers[' ABC' ] = ' some value to send' ;
1186
+ }
1187
+ stream .respondWithFile (' /some/file' ,
1188
+ { ' content-type' : ' text/plain' },
1189
+ { getTrailers });
1190
+ });
1191
+ ```
1192
+
1193
+ * Note* : The HTTP/1 specification forbids trailers from containing HTTP/2
1194
+ "pseudo-header" fields (e.g. ` ':status' ` , ` ':path' ` , etc). An ` 'error' ` event
1195
+ will be emitted if the ` getTrailers ` callback attempts to set such header
1196
+ fields.
1197
+
1123
1198
### Class: Http2Server
1124
1199
<!-- YAML
1125
1200
added: REPLACEME
0 commit comments