Skip to content

Commit

Permalink
fix: Allow to set custom user agent (usebruno#3146)
Browse files Browse the repository at this point in the history
Co-authored-by: Linhart Lukáš <Lukas.Linhart@tescosw.cz>
  • Loading branch information
panda7789 and Linhart Lukáš authored Sep 20, 2024
1 parent 89c8956 commit dd2b93e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/bruno-cli/src/utils/axios-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ const { CLI_VERSION } = require('../constants');
*/
function makeAxiosInstance() {
/** @type {axios.AxiosInstance} */
const instance = axios.create();
const instance = axios.create({
headers: {
"User-Agent": `bruno-runtime/${CLI_VERSION}`
}
});

instance.interceptors.request.use((config) => {
config.headers['request-start-time'] = Date.now();
config.headers['user-agent'] = `bruno-runtime/${CLI_VERSION}`;
return config;
});

Expand Down
8 changes: 5 additions & 3 deletions packages/bruno-electron/src/ipc/network/axios-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const electronApp = require("electron");
const LOCAL_IPV6 = '::1';
const LOCAL_IPV4 = '127.0.0.1';
const LOCALHOST = 'localhost';
const version = electronApp?.app?.getVersion()?.substring(1) ?? "";

const getTld = (hostname) => {
if (!hostname) {
Expand Down Expand Up @@ -66,9 +67,11 @@ function makeAxiosInstance() {
}, this);
return data;
},
proxy: false
proxy: false,
headers: {
"User-Agent": `bruno-runtime/${version}`
}
});
const version = electronApp?.app?.getVersion()?.substring(1) ?? "";

instance.interceptors.request.use(async (config) => {
const url = URL.parse(config.url);
Expand All @@ -88,7 +91,6 @@ function makeAxiosInstance() {
}

config.headers['request-start-time'] = Date.now();
config.headers['user-agent'] = `bruno-runtime/${version}`;
return config;
});

Expand Down

0 comments on commit dd2b93e

Please sign in to comment.