fix: allow user to delete default bruno headers in pre-request (#7331)

* fix: allow user to delete default bruno headers

* fix: resolved comments

---------

Co-authored-by: shubh-bruno <shubh-bruno@shubh-bruno.local>
This commit is contained in:
shubh-bruno
2026-03-03 14:35:54 +05:30
committed by GitHub
parent bba0e97435
commit ca0412b58b
5 changed files with 219 additions and 29 deletions

View File

@@ -78,14 +78,35 @@ function makeAxiosInstance({ requestMaxRedirects = 5, disableCookies, followRedi
const instance = axios.create({
proxy: false,
maxRedirects: 0,
headers: {
'User-Agent': `bruno-runtime/${CLI_VERSION}`
}
headers: {}
});
// Set User-Agent manually (using transformRequest to delete headers instead)
instance.defaults.headers.common = {
'User-Agent': `bruno-runtime/${CLI_VERSION}`
};
instance.interceptors.request.use((config) => {
config.headers['request-start-time'] = Date.now();
/**
Apply header deletions requested via req.deleteHeader() in pre-request scripts.
Using set(name, null) rather than delete(): the axios http adapter guards its
own defaults (User-Agent, Accept-Encoding) with set(..., false) which only
skips writing when the key already exists. delete() removes the key entirely,
so the guard misses and the adapter re-adds the default. null keeps the key
present (blocking the guard) while toJSON() omits null values from the wire.
*/
const headersToDelete = config.__headersToDelete;
if (headersToDelete && Array.isArray(headersToDelete)) {
headersToDelete.forEach((headerName) => {
const lower = headerName.toLowerCase();
if (lower === 'host' || lower === 'connection') return;
config.headers.set(headerName, null);
});
delete config.__headersToDelete;
}
// Add cookies to request if available and not disabled
if (!disableCookies) {
const cookieString = getCookieStringForUrl(config.url);