Skip to content

Drop a "Content-Type" header, if any, for multipart requests#654

Merged
dakrone merged 3 commits into
dakrone:3.xfrom
marksto:fix-multipart-headers
Jun 18, 2025
Merged

Drop a "Content-Type" header, if any, for multipart requests#654
dakrone merged 3 commits into
dakrone:3.xfrom
marksto:fix-multipart-headers

Conversation

@marksto

@marksto marksto commented Jun 12, 2025

Copy link
Copy Markdown
Contributor

@dakrone Hi Lee!

This one is focused and straightforward.

It fixes a malformed multipart request in case if it goes with its own "content-type" header. In this case, an Apache HTTP Client's FormBodyPartBuilder won't be able to set a correct "content-type" header that contains the required boundary value. This, in turn, will lead to inability to process the request properly on a server side and can usually be observed as a "400 Bad request" response status code.

This patch simply filters out request headers named "content-type" / "Content-Type" in case of a :multipart request.

Cheers,
Mark

@dakrone

dakrone commented Jun 13, 2025

Copy link
Copy Markdown
Owner

Thanks @marksto, this generally looks good to me. Would you mind adding a test that ensures the correct behavior so we don't inadvertently undo this change at a later time?

@marksto

marksto commented Jun 13, 2025

Copy link
Copy Markdown
Contributor Author

@dakrone Totally second this! Pardon for being lazy yesterday. The investigation into this case required all the calories. 😅

This one is subtle as it has more to do with the Apache HttpClient internals rather than with the clj-http by itself, so it's better be covered.

Tests are now included.

@marksto marksto force-pushed the fix-multipart-headers branch from 2b63846 to 243d624 Compare June 13, 2025 18:26
@marksto marksto changed the title Drop a "content-type" header, if any, for multipart requests Drop a "Content-Type" header, if any, for multipart requests Jun 13, 2025

@dakrone dakrone left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I will merge after #655 and doing some local testing. Thanks!

@dakrone dakrone merged commit b07de01 into dakrone:3.x Jun 18, 2025
0 of 12 checks passed
@dakrone

dakrone commented Jun 18, 2025

Copy link
Copy Markdown
Owner

Thanks for fixing this @marksto!

@marksto

marksto commented Jun 18, 2025

Copy link
Copy Markdown
Contributor Author

@dakrone Thanks for incorporating the fix! It would be nice to see a new release of the lib soonish.

@dakrone

dakrone commented Jun 26, 2025

Copy link
Copy Markdown
Owner

@marksto I've release 3.13.1 with this fix; thanks!

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