fix: preserve axios default Accept header when setting User-Agent (#7820)

Assigning `defaults.headers.common = { 'User-Agent': ... }` replaced the
entire common headers object, nuking axios's built-in default:

  Accept: application/json, text/plain, */*

This caused servers relying on content-negotiation to receive requests
with no Accept header. Fix by extending the existing object with a
property assignment instead.

Add regression tests for both electron and CLI axios instances verifying
that Accept is preserved and User-Agent is set correctly.

Co-authored-by: Pragadesh-45 <temporaryg7904@gmail.com>
This commit is contained in:
James
2026-05-05 17:08:12 +01:00
committed by GitHub
parent ab7dd1ff26
commit b91f9ba5be
5 changed files with 97 additions and 8 deletions

View File

@@ -92,10 +92,11 @@ function makeAxiosInstance({
headers: {}
});
// Set User-Agent manually (using transformRequest to delete headers instead)
instance.defaults.headers.common = {
'User-Agent': `bruno-runtime/${CLI_VERSION}`
};
// Extend common headers with User-Agent rather than replacing the object.
// axios.create() preserves defaults.headers.common = { Accept: 'application/json, text/plain, */*' }.
// Assigning a new object (= { 'User-Agent': ... }) would nuke that default, causing servers that
// rely on content-negotiation to receive requests with no Accept header.
instance.defaults.headers.common['User-Agent'] = `bruno-runtime/${CLI_VERSION}`;
instance.interceptors.request.use((config) => {
config.headers['request-start-time'] = Date.now();