mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-16 04:11:29 +00:00
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>
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
const { describe, it, expect } = require('@jest/globals');
|
|
const { makeAxiosInstance } = require('../../src/utils/axios-instance');
|
|
|
|
function createStubAdapter() {
|
|
let capturedConfig = null;
|
|
|
|
const adapter = (config) => {
|
|
capturedConfig = config;
|
|
return Promise.resolve({ data: {}, status: 200, statusText: 'OK', headers: {}, config });
|
|
};
|
|
|
|
adapter.getConfig = () => capturedConfig;
|
|
|
|
return adapter;
|
|
}
|
|
|
|
describe('makeAxiosInstance', () => {
|
|
it('setting User-Agent does not clobber the axios default Accept header', async () => {
|
|
const stubAdapter = createStubAdapter();
|
|
const instance = makeAxiosInstance();
|
|
|
|
await instance({ url: 'https://api.example.com/test', method: 'get', adapter: stubAdapter });
|
|
|
|
// axios.create() sets Accept by default; assigning a new object to defaults.headers.common
|
|
// would nuke it. Guard against that regression.
|
|
expect(stubAdapter.getConfig().headers['Accept']).toMatch(/application\/json/);
|
|
});
|
|
|
|
it('sets User-Agent header to bruno-runtime version', async () => {
|
|
const stubAdapter = createStubAdapter();
|
|
const instance = makeAxiosInstance();
|
|
|
|
await instance({ url: 'https://api.example.com/test', method: 'get', adapter: stubAdapter });
|
|
|
|
expect(stubAdapter.getConfig().headers['User-Agent']).toMatch(/^bruno-runtime\//);
|
|
});
|
|
});
|