import { AxiosHeaders, type InternalAxiosRequestConfig } from 'axios' /** Matches the end-to-end upload timeout policy at the Nginx boundary. */ export const FORM_DATA_UPLOAD_TIMEOUT_MS = 60_000 /** * Keep FormData intact through Axios transformRequest. Axios' browser adapter * already lets the browser generate the multipart boundary; deleting a stale * JSON or manually supplied content type here ensures FormData is not * serialized as JSON before the adapter gets it. */ export function applyFormDataRequestDefaults(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig { if (typeof FormData === 'undefined' || !(config.data instanceof FormData)) { return config } const headers = AxiosHeaders.from(config.headers) headers.delete('Content-Type') config.headers = headers if (config.timeout === undefined || config.timeout === 0) { config.timeout = FORM_DATA_UPLOAD_TIMEOUT_MS } return config }