#11247·axios

AxiosHeaders set() never calls a rewrite function, so the header is never overwritten

Author: PrafylCreated Sep 23, 2026Updated Sep 23, 2026

the docs for AxiosHeaders#set say the rewrite argument can be a function that decides whether to overwrite the header, and index.d.ts types it as boolean | AxiosHeaderMatcher. but setHeader in lib/core/AxiosHeaders.js only checks for true and undefined, so anything else behaves like false. the function never runs and the existing header is never replaced. same thing for a string or RegExp, and for the accessors like setContentType(value, rewrite).

javascript
import { AxiosHeaders } from "axios";

let called = false;
const headers = new AxiosHeaders({ "Content-Type": "text/plain" });
headers.set("Content-Type", "application/json", () => (called = true));

console.log(headers.get("Content-Type"), called); // text/plain false

this is on 1.20.0 and v2.x has the same check. has() and delete() already take the same kind of matcher through matchHeaderValue, so set() should probably do the same and only replace the header when the matcher accepts its current value. im sending a PR for that with a test.