fix: drop placeholder Content-Type from postForm/putForm/patchForm#10909
fix: drop placeholder Content-Type from postForm/putForm/patchForm#10909mixelburg wants to merge 2 commits into
Conversation
jasonsaayman
left a comment
There was a problem hiding this comment.
I think we may need a transitional property; otherwise, this would be a breaking change we cannot release. If we can address that and then add some very solid testing here that would probably help this land!
There was a problem hiding this comment.
2 issues found across 3 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/unit/formMethods.test.js">
<violation number="1" location="tests/unit/formMethods.test.js:22">
P1: These tests assert the old placeholder `Content-Type: multipart/form-data` behavior by default, which conflicts with the PR’s fix to stop injecting that header.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| @@ -0,0 +1,116 @@ | |||
| /** | |||
There was a problem hiding this comment.
P1: These tests assert the old placeholder Content-Type: multipart/form-data behavior by default, which conflicts with the PR’s fix to stop injecting that header.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/unit/formMethods.test.js, line 22:
<comment>These tests assert the old placeholder `Content-Type: multipart/form-data` behavior by default, which conflicts with the PR’s fix to stop injecting that header.</comment>
<file context>
@@ -0,0 +1,116 @@
+
+describe('form method helpers (postForm/putForm/patchForm)', () => {
+ describe('default behaviour (transitional.formDataContentType = true)', () => {
+ it('postForm sets placeholder Content-Type: multipart/form-data by default', async () => {
+ let capturedConfig;
+ const instance = axios.create({ adapter: (cfg) => { capturedConfig = cfg; return mockAdapter(cfg); } });
</file context>
|
Without a header placeholder, there would be no sense in the existence of these methods. Axios serializes the request body based on the headers, and the payload object is serialized as a form, not as JSON, when the form header is set. That's why the header placeholder is highly necessary. These methods were introduced to avoid manually setting this header. Otherwise, it would be necessary to introduce an option like axios.post('https://httpbin.org/post', { x: 1 }); // => application/json
axios.postForm('https://httpbin.org/post', { x: 1 }); // => multipart/form-dataSo, issues of correctly setting headers for the platform should be addressed in the adapter itself. When these methods were introduced, FormData in ReactNative required the |
|
@mixelburg, please let us know if you can address the cubic review comments and look at @DigitalBrainJS comments, please. |
…tchForm Adds `transitional.formDataContentType` (default `true`) to control whether postForm/putForm/patchForm inject the placeholder `Content-Type: multipart/form-data` header. Set to `false` globally or per-request to let the adapter/platform set the correct Content-Type with boundary — fixes React Native Android where the placeholder without a boundary is rejected by the networking layer (issue axios#10886). This keeps backward compat (existing code unaffected by default) while providing a migration path before a future major-version default flip to `false`.
ab1fd44 to
4ded3d5
Compare
|
Closing see #10898 |
Fixes #10886.
postForm/putForm/patchFormwere settingContent-Type: multipart/form-dataas a placeholder, relying on adapters to overwrite it with the real boundary later. This breaks on React Native Android — RN is nothasStandardBrowserEnv, so the bare placeholder (without boundary) reaches the wire and Android's networking layer rejects it.The placeholder is unnecessary: adapters that handle FormData already manage the Content-Type themselves (browser XHR lets the platform set it, Node form-data uses
getHeaders(), fetch usesformDataToStream). Dropping it from the overlay config causes no change for those adapters and fixes the RN Android case.Summary by cubic
Adds
transitional.formDataContentTypeto control the placeholderContent-TypeinpostForm/putForm/patchForm. Set it to false to drop the placeholder so the adapter/platform sets the correct boundary, fixing React Native Android.Description
transitional.formDataContentType(default true).Content-Type; adapters/platforms set it.transitional; per-request overrides.multipart/form-datawithout a boundary.Docs
Please update
/docs/to covertransitional.formDataContentTypewith global and per-request examples, and recommend setting it to false on React Native Android.Testing
Added
tests/unit/formMethods.test.js:multipart/form-data.postunaffected.Semantic version impact
Minor: adds a backward-compatible flag with the default preserving current behavior.
Written for commit 4ded3d5. Summary will update on new commits.