[PR #20323] fix(http): force multipart/form-data even without files(#20322) #29364

Closed
opened 2026-02-21 20:45:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/20323

State: closed
Merged: Yes


Summary

This PR ensures that HTTP request nodes correctly trigger multipart/form-data encoding, even when no actual files are present.

Previously, although the request appeared to be multipart/form-data in the request dump, the actual HTTP request was interpreted as application/x-www-form-urlencoded by backend servers.

To resolve this, i insert a harmless placeholder field named __multipart_placeholder__ when no files are present. This forces httpx to properly set the multipart/form-data content type.


As a developer working on API gateway infrastructure, I encountered this inconsistency while testing with Dify and Spring. Tools like Postman properly preserve the multipart content-type even with empty forms, but Dify failed to do so.

To confirm this behavior, I created a Spring-based test controller that logged the actual Content-Type header and validated whether MultipartHttpServletRequest was recognized. Screenshots are attached below for both the "before" and "after" cases.

This change has been verified using a local test controller that replicates the server behavior. The added field is a harmless placeholder that is safely ignored by the server, ensuring full compatibility with existing behavior.

Close #20322

Screenshots

Phase Request 1 Request 2 Spring Server Log
Before req1 req2 log1
After req3 req4 log2

Checklist

  • [ ] This change requires a documentation update, included: Dify Document
  • [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.
  • [x] I ran dev/reformat (backend) and cd web && npx lint-staged (frontend) to appease the lint gods.
**Original Pull Request:** https://github.com/langgenius/dify/pull/20323 **State:** closed **Merged:** Yes --- <h1>Summary</h1> <blockquote> <p>This PR ensures that HTTP request nodes correctly trigger multipart/form-data encoding, even when no actual files are present.</p> </blockquote> <p>Previously, although the request appeared to be <code>multipart/form-data</code> in the request dump, the actual HTTP request was interpreted as <code>application/x-www-form-urlencoded</code> by backend servers.</p> <p>To resolve this, i insert a harmless placeholder field named <code>__multipart_placeholder__</code> when no files are present. This forces <code>httpx</code> to properly set the <code>multipart/form-data</code> content type.</p> <hr> <p>As a developer working on API gateway infrastructure, I encountered this inconsistency while testing with Dify and Spring. Tools like Postman properly preserve the multipart content-type even with empty forms, but Dify failed to do so.</p> <p>To confirm this behavior, I created a Spring-based test controller that logged the actual <code>Content-Type</code> header and validated whether <code>MultipartHttpServletRequest</code> was recognized. Screenshots are attached below for both the &quot;before&quot; and &quot;after&quot; cases.</p> <p>This change has been verified using a local test controller that replicates the server behavior. The added field is a harmless placeholder that is safely ignored by the server, ensuring full compatibility with existing behavior.</p> Close #20322 <h1>Screenshots</h1> | Phase | Request 1 | Request 2 | Spring Server Log | |---------|-----------|-----------|--------------------| | **Before** | ![req1](https://github.com/user-attachments/assets/c5e53d6d-5c17-403a-8726-db2c4e7f6873) | ![req2](https://github.com/user-attachments/assets/e34fad8d-18d3-45a5-9ff1-272939f32265) | ![log1](https://github.com/user-attachments/assets/6aded5b7-7813-40a1-9a67-ef05f0bb6ba1) | | **After** | ![req3](https://github.com/user-attachments/assets/0deda12d-8d1c-4645-947a-1b1511b507b9) | ![req4](https://github.com/user-attachments/assets/618059d6-f5d6-4c40-b00b-c11192ef0e3d) | ![log2](https://github.com/user-attachments/assets/edd56841-ca1d-4a0e-9e88-e9fc301791e3) | <h1>Checklist</h1> <ul> <li>[ ] This change requires a documentation update, included: <a href="https://github.com/langgenius/dify-docs">Dify Document</a></li> <li>[x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)</li> <li>[x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.</li> <li>[x] I've updated the documentation accordingly.</li> <li>[x] I ran <code>dev/reformat</code> (backend) and <code>cd web &amp;&amp; npx lint-staged</code> (frontend) to appease the lint gods.</li> </ul>
yindo added the pull-request label 2026-02-21 20:45:24 -05:00
yindo closed this issue 2026-02-21 20:45:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29364