nodejs / nodejs/undici

How can I use fixed-length multipart request with FormData?

Open
#1,421 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
7.7k
Forks
880
Avg merge
2d 16h
Merged PRs (30d)
68

Description

Discussed in https://github.com/nodejs/undici/discussions/1420

Originally posted by nwtgck May 6, 2022
Hi, I'd like to request a fixed-length multipart request. The code below requested with transfer-encoding: chunked without content-length. I assume the length of formData is statically decided.

const undici = require("undici");

(async () => {
  const formData = new undici.FormData();
  formData.append("myname", "myvalue");
  const res = await undici.request("http://localhost:8181", {
    body: formData,
  });
})();
$ nc -lp 8181
PUT / HTTP/1.1
host: localhost:8181
connection: keep-alive
content-type: multipart/form-data; boundary=----formdata-undici-0.5140957512643098
transfer-encoding: chunked

64
------formdata-undici-0.5140957512643098
Content-Disposition: form-data; name="myname"

myvalue

2a
------formdata-undici-0.5140957512643098--
0
```</div>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The entry points shown are undici.FormData and undici.request; start by tracing how FormData is serialized and how request selects transfer encoding. Compare the result with the provided netcat output, and consider the work complete when a fixed-length multipart request sends Content-Length instead of transfer-encoding: chunked.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.