fix(ui): preserve multipart Content-Type in apiFetch (RAN-34)#78
Merged
Conversation
apiFetch was unconditionally defaulting Content-Type to application/json for any request with a body. That broke FormData uploads (and any other browser-managed body) because the Fetch implementation no longer added the multipart boundary, so the Documents UploadModal posted an unparseable body to /api/upload. - Skip the JSON default for FormData, Blob, URLSearchParams, ReadableStream, ArrayBuffer, and typed-array bodies; the runtime attaches the right Content-Type (with boundary, etc.) for those. - Continue defaulting application/json for string bodies, and respect a caller-provided Content-Type without overriding it. - Add regression tests in ui/src/lib/__tests__/api-client.test.ts that fail when FormData / Blob / URLSearchParams / ArrayBuffer / typed arrays receive a defaulted JSON Content-Type, plus coverage for string-body defaulting and explicit-header passthrough. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
apiFetchwas unconditionally defaultingContent-Type: application/jsonfor any request that carried a body. That brokeFormDatauploads (and any other browser-managed body type) because the runtime could no longer attach the multipart boundary, so the DocumentsUploadModalposted an unparseable body to/api/upload.FormData,Blob,URLSearchParams,ReadableStream,ArrayBuffer, and typed-array bodies — the runtime owns theContent-Typefor those (boundary, encoding, etc.).application/jsonfor string bodies and always respect a caller-providedContent-Type.ui/src/lib/__tests__/api-client.test.tsthat would fail if a multipart upload silently got aContent-Type: application/jsoninjected, plus coverage for string-body defaulting and explicit-header passthrough.Tracks RAN-34 (parent: RAN-7 reviewer finding).
Test plan
cd ui && npm test— 28 files / 92 tests pass, including 4 newapiFetchregression testscd ui && npm run typecheck— cleancd ui && npm run build— clean/api/uploadfrom the Documents modal once mergednpm run lintis broken onmain(eslint v10 needseslint.config.js, repo has neither flat config nor.eslintrc.*). Out of scope for this PR.