-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix redirect interceptor with FormData body (#3815)
fix redirect interceptor with FormData body
- Loading branch information
Showing
5 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
const { FormData, request, Agent, interceptors } = require('../..') | ||
const { test } = require('node:test') | ||
const { createServer } = require('node:http') | ||
const { once } = require('node:events') | ||
const { tspl } = require('@matteo.collina/tspl') | ||
|
||
test('redirecting works with a FormData body', async (t) => { | ||
const plan = tspl(t, { plan: 1 }) | ||
|
||
const server = createServer((req, res) => { | ||
if (req.url === '/1') { | ||
res.writeHead(302, undefined, { location: '/2' }) | ||
res.end() | ||
} else { | ||
res.end('OK') | ||
} | ||
}).listen(0) | ||
|
||
t.after(() => server.close()) | ||
await once(server, 'listening') | ||
|
||
const agent = new Agent().compose(interceptors.redirect({ maxRedirections: 1 })) | ||
|
||
const body = new FormData() | ||
body.append('hello', 'world') | ||
|
||
const { context } = await request(`http://localhost:${server.address().port}/1`, { | ||
body, | ||
method: 'POST', | ||
dispatcher: agent, | ||
maxRedirections: 1 | ||
}) | ||
|
||
plan.deepStrictEqual(context.history, [ | ||
new URL(`http://localhost:${server.address().port}/1`), | ||
new URL(`http://localhost:${server.address().port}/2`) | ||
]) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters