@@ -21,6 +21,7 @@ import {
21
21
defaultNodeConnectionHeader
22
22
} from "../../test-utils" ;
23
23
import { isLocalIPv6Available } from "../../../src/util/socket-util" ;
24
+ import { streamToBuffer } from "../../../src/util/buffer-utils" ;
24
25
25
26
const INITIAL_ENV = _ . cloneDeep ( process . env ) ;
26
27
@@ -138,6 +139,43 @@ nodeOnly(() => {
138
139
expect ( response . statusCode ) . to . equal ( 200 ) ; // Callback expectations should run OK
139
140
} ) ;
140
141
142
+ it ( "should be able to pass through request trailers" , async ( ) => {
143
+ await remoteServer . forAnyRequest ( ) . thenCallback ( async ( req ) => {
144
+ const trailers = req . rawTrailers ;
145
+ expect ( trailers ) . to . deep . equal ( [
146
+ [ 'trailer-NAME' , 'trailer-value' ]
147
+ ] ) ;
148
+
149
+ return {
150
+ statusCode : 200 ,
151
+ body : 'Found expected trailers'
152
+ } ;
153
+ } ) ;
154
+
155
+ await server . forAnyRequest ( ) . thenPassThrough ( ) ;
156
+
157
+ const request = http . request ( {
158
+ method : 'POST' ,
159
+ hostname : 'localhost' ,
160
+ port : server . port ,
161
+ headers : {
162
+ 'Trailer' : 'trailer-name' ,
163
+ 'Host' : `localhost:${ remoteServer . port } ` // Manually proxy upstream
164
+ }
165
+ } ) ;
166
+
167
+ request . addTrailers ( { 'trailer-NAME' : 'trailer-value' } ) ;
168
+ request . end ( ) ;
169
+
170
+ const response = await new Promise < http . IncomingMessage > ( ( resolve ) =>
171
+ request . on ( 'response' , resolve )
172
+ ) ;
173
+
174
+ expect ( response . statusCode ) . to . equal ( 200 ) ;
175
+ expect ( ( await streamToBuffer ( response ) ) . toString ( 'utf8' ) )
176
+ . to . equal ( 'Found expected trailers' ) ;
177
+ } ) ;
178
+
141
179
it ( "should be able to pass back response headers" , async ( ) => {
142
180
await remoteServer . forAnyRequest ( ) . thenCallback ( async ( req ) => ( {
143
181
statusCode : 200 ,
@@ -166,6 +204,40 @@ nodeOnly(() => {
166
204
] ) ;
167
205
} ) ;
168
206
207
+ it ( "should be able to pass back response trailers" , async ( ) => {
208
+ await remoteServer . forAnyRequest ( ) . thenCallback ( async ( req ) => ( {
209
+ statusCode : 200 ,
210
+ body : await req . body . getText ( ) ,
211
+ headers : {
212
+ 'Trailer' : 'trailer-name' ,
213
+ 'Transfer-Encoding' : 'chunked'
214
+ } ,
215
+ trailers : {
216
+ 'Trailer-Name' : 'trailer-value' // N.b thenCallback is not case sensitive (yet?)
217
+ }
218
+ } ) ) ;
219
+
220
+ await server . forAnyRequest ( ) . thenPassThrough ( ) ;
221
+
222
+ const request = http . request ( {
223
+ method : 'GET' ,
224
+ hostname : 'localhost' ,
225
+ port : server . port ,
226
+ headers : {
227
+ 'Host' : `localhost:${ remoteServer . port } ` // Manually proxy upstream
228
+ }
229
+ } ) . end ( ) ;
230
+
231
+ const response = await new Promise < http . IncomingMessage > ( ( resolve ) =>
232
+ request . on ( 'response' , resolve )
233
+ ) ;
234
+
235
+ await streamToBuffer ( response ) ; // Wait for response to complete
236
+ expect ( response . rawTrailers ) . to . deep . equal ( [
237
+ 'Trailer-Name' , 'trailer-value'
238
+ ] ) ;
239
+ } ) ;
240
+
169
241
it ( "should be able to pass through requests with a body" , async ( ) => {
170
242
await remoteServer . forAnyRequest ( ) . thenCallback ( async ( req ) => ( {
171
243
statusCode : 200 ,
0 commit comments