@@ -13,6 +13,7 @@ const {
1313 startRedirectingWithQueryParams
1414} = require ( './utils/redirecting-servers' )
1515const { createReadable, createReadableStream } = require ( './utils/stream' )
16+ const { Headers : UndiciHeaders } = require ( '..' )
1617const redirect = undici . interceptors . redirect
1718
1819for ( const factory of [
@@ -227,7 +228,7 @@ for (const factory of [
227228 await t . completed
228229 } )
229230
230- test ( 'should remove Host and request body related headers when following HTTP 303 (Headers)' , async t => {
231+ test ( 'should remove Host and request body related headers when following HTTP 303 (Global Headers)' , async t => {
231232 t = tspl ( t , { plan : 3 } )
232233
233234 const server = await startRedirectingServer ( )
@@ -255,6 +256,62 @@ for (const factory of [
255256 await t . completed
256257 } )
257258
259+ test ( 'should remove Host and request body related headers when following HTTP 303 (Undici Headers)' , async t => {
260+ t = tspl ( t , { plan : 3 } )
261+
262+ const server = await startRedirectingServer ( )
263+
264+ const { statusCode, headers, body : bodyStream } = await request ( t , server , undefined , `http://${ server } /303` , {
265+ method : 'PATCH' ,
266+ headers : new UndiciHeaders ( {
267+ 'Content-Encoding' : 'gzip' ,
268+ 'X-Foo1' : '1' ,
269+ 'X-Foo2' : '2' ,
270+ 'Content-Type' : 'application/json' ,
271+ 'X-Foo3' : '3' ,
272+ Host : 'localhost' ,
273+ 'X-Bar' : '4'
274+ } ) ,
275+ maxRedirections : 10
276+ } )
277+
278+ const body = await bodyStream . text ( )
279+
280+ t . strictEqual ( statusCode , 200 )
281+ t . ok ( ! headers . location )
282+ t . strictEqual ( body , `GET /5 :: host@${ server } connection@keep-alive x-bar@4 x-foo1@1 x-foo2@2 x-foo3@3` )
283+
284+ await t . completed
285+ } )
286+
287+ test ( 'should remove Host and request body related headers when following HTTP 303 (Maps)' , async t => {
288+ t = tspl ( t , { plan : 3 } )
289+
290+ const server = await startRedirectingServer ( )
291+
292+ const { statusCode, headers, body : bodyStream } = await request ( t , server , undefined , `http://${ server } /303` , {
293+ method : 'PATCH' ,
294+ headers : new Map ( [
295+ [ 'Content-Encoding' , 'gzip' ] ,
296+ [ 'X-Foo1' , '1' ] ,
297+ [ 'X-Foo2' , '2' ] ,
298+ [ 'Content-Type' , 'application/json' ] ,
299+ [ 'X-Foo3' , '3' ] ,
300+ [ 'Host' , 'localhost' ] ,
301+ [ 'X-Bar' , '4' ]
302+ ] ) ,
303+ maxRedirections : 10
304+ } )
305+
306+ const body = await bodyStream . text ( )
307+
308+ t . strictEqual ( statusCode , 200 )
309+ t . ok ( ! headers . location )
310+ t . strictEqual ( body , `GET /5 :: host@${ server } connection@keep-alive x-foo1@1 x-foo2@2 x-foo3@3 x-bar@4` )
311+
312+ await t . completed
313+ } )
314+
258315 test ( 'should follow redirection after a HTTP 307' , async t => {
259316 t = tspl ( t , { plan : 3 } )
260317
0 commit comments