Skip to content

Conversation

@das7pad
Copy link
Contributor

@das7pad das7pad commented Oct 29, 2025

Hi!

For jenkinsci/jenkins#11177 we need basic support for multipart/form-data responses. I would like to contribute a simple implementation for it. It only handles the happy path well. Based on mozilla/rhino#1941, I take that a proper Fetch API implementation is planned for the long-term.

Testing:

  • Copy and paste the contents of src/main/resources/org/htmlunit/javascript/polyfill/fetch/fetch.umd.js into the dev-tools of a browser
  • Parse the sample multipart/form-data response from the tests
r=new window.WHATWGFetch.Response(
  "--0123456789\r\nContent-Disposition: form-data;name=test0\r\nContent-Type: text/plain\r\n\r\nHello1\nHello1\r\n--0123456789\r\nContent-Disposition: form-data;name=test1\r\nContent-Type: text/plain\r\n\r\nHello2\nHello2\r\n--0123456789--",
  { headers: { 'Content-Type': "multipart/form-data; boundary=0123456789"} }
);
f=await r.formData();
console.assert(f.get('test0') === 'Hello1\nHello1');
console.assert(f.get('test1') === 'Hello2\nHello2');
console.log(Object.fromEntries(Array.from(f.entries())));

It asserts that the two parts are properly parsed and prints them:

{test0: 'Hello1\nHello1', test1: 'Hello2\nHello2'}

@rbri
Copy link
Member

rbri commented Oct 30, 2025

@das7pad thanks for that. This is just in time and a great motivation. Have started some days ago with writing some fetch test to start a real impl (not that polyfill) for fetch. Will take your request her more as a motivation to finish that (hopefully with the 4.19.0 release.

Will have a look at this and maybe squezze it into 4.18.0.

@rbri rbri merged commit 777105a into HtmlUnit:master Oct 30, 2025
5 of 6 checks passed
@rbri
Copy link
Member

rbri commented Oct 30, 2025

Merged, adjusted, and some HtmlUnit fixes done. Your case passes now.
Thanks for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants