-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set content-length when using FormData body w/ request (#2066)
* fix: set content-length when using FormData body w/ request * import FormData
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 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,30 @@ | ||
'use strict' | ||
|
||
const { test, skip } = require('tap') | ||
const { nodeMajor, nodeMinor } = require('../lib/core/util') | ||
const { createServer } = require('http') | ||
const { once } = require('events') | ||
const { File, FormData, request } = require('..') | ||
|
||
if (nodeMajor < 16 || (nodeMajor === 16 && nodeMinor < 8)) { | ||
skip('FormData is not available in node < v16.8.0') | ||
process.exit() | ||
} | ||
|
||
test('undici.request with a FormData body should set content-length header', async (t) => { | ||
const server = createServer((req, res) => { | ||
t.ok(req.headers['content-length']) | ||
res.end() | ||
}).listen(0) | ||
|
||
t.teardown(server.close.bind(server)) | ||
await once(server, 'listening') | ||
|
||
const body = new FormData() | ||
body.set('file', new File(['abc'], 'abc.txt')) | ||
|
||
await request(`http://localhost:${server.address().port}`, { | ||
method: 'POST', | ||
body | ||
}) | ||
}) |