summaryrefslogtreecommitdiffstats
path: root/test/issue-2065.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
commit0b6210cd37b68b94252cb798598b12974a20e1c1 (patch)
treee371686554a877842d95aa94f100bee552ff2a8e /test/issue-2065.js
parentInitial commit. (diff)
downloadnode-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz
node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--test/issue-2065.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/issue-2065.js b/test/issue-2065.js
new file mode 100644
index 0000000..cc288c4
--- /dev/null
+++ b/test/issue-2065.js
@@ -0,0 +1,71 @@
+'use strict'
+
+const { test, skip } = require('tap')
+const { nodeMajor, nodeMinor } = require('../lib/core/util')
+const { createServer } = require('http')
+const { once } = require('events')
+const { createReadStream } = require('fs')
+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
+ })
+})
+
+test('undici.request with a FormData stream value should set transfer-encoding header', async (t) => {
+ const server = createServer((req, res) => {
+ t.equal(req.headers['transfer-encoding'], 'chunked')
+ res.end()
+ }).listen(0)
+
+ t.teardown(server.close.bind(server))
+ await once(server, 'listening')
+
+ class BlobFromStream {
+ #stream
+ #type
+ constructor (stream, type) {
+ this.#stream = stream
+ this.#type = type
+ }
+
+ stream () {
+ return this.#stream
+ }
+
+ get type () {
+ return this.#type
+ }
+
+ get [Symbol.toStringTag] () {
+ return 'Blob'
+ }
+ }
+
+ const body = new FormData()
+ const fileReadable = createReadStream(__filename)
+ body.set('file', new BlobFromStream(fileReadable, '.js'), 'streamfile')
+
+ await request(`http://localhost:${server.address().port}`, {
+ method: 'POST',
+ body
+ })
+})