mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
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:
@@ -20,6 +20,7 @@ import https from 'node:https';
|
||||
|
||||
type ModifiedInternalAxiosRequestConfig = InternalAxiosRequestConfig & {
|
||||
startTime: number;
|
||||
__headersToDelete?: string[];
|
||||
};
|
||||
|
||||
type ModifiedAxiosResponse = AxiosResponse & {
|
||||
@@ -51,10 +52,28 @@ const makeAxiosInstance = (customRequestConfig?: AxiosRequestConfig) => {
|
||||
customRequestConfig = customRequestConfig || {};
|
||||
const axiosInstance = axios.create({
|
||||
...baseRequestConfig,
|
||||
...customRequestConfig
|
||||
...customRequestConfig,
|
||||
headers: {}
|
||||
});
|
||||
|
||||
axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
||||
// Apply header deletions requested via req.deleteHeader() in pre-request scripts.
|
||||
const modConfig = config as ModifiedInternalAxiosRequestConfig;
|
||||
const headersToDelete = modConfig.__headersToDelete;
|
||||
if (headersToDelete && Array.isArray(headersToDelete)) {
|
||||
headersToDelete.forEach((headerName: string) => {
|
||||
const lower = headerName.toLowerCase();
|
||||
if (lower === 'host' || lower === 'connection') return;
|
||||
// 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.
|
||||
config.headers.set(headerName, null);
|
||||
});
|
||||
delete modConfig.__headersToDelete;
|
||||
}
|
||||
|
||||
const modifiedConfig: ModifiedInternalAxiosRequestConfig = {
|
||||
...config,
|
||||
startTime: Date.now()
|
||||
|
||||
Reference in New Issue
Block a user