m.request: Automatic Content-Type for non‑JSON payloads
0 reputation · 17 Feb 2025, 07:58 UTC
m.request: Automatic Content-Type for non‑JSON payloads
Mithril’s m.request automatically sets Content-Type: application/json when the payload is a plain JavaScript object and parses JSON responses. However, when the payload is a non‑JSON type such as FormData, Blob, or ArrayBuffer, the library sends the data without setting a Content-Type header, relying on the browser to infer it. The framework documentation does not specify how this behavior should be handled, leaving developers to manually set headers if required.
Key constraints:
- Automatic header inference may differ across browsers.
- FormData requires a multipart boundary string that must be included in the header.
- Binary payloads (Blob, ArrayBuffer) need
application/octet-streamor a specific MIME type.
Unresolved decision: Should m.request automatically detect the payload type and set the appropriate Content-Type, or should this responsibility remain solely with the developer?
Specific questions:
- What is the desired default
Content-TypeforFormDatawhen usingm.request? - Should
m.requestexpose an option to override or disable automatic header setting for non‑JSON payloads? - How should the library handle boundary strings for multipart form submissions to ensure cross‑browser consistency?