fix: Allow to set custom user agent (#3146)

Co-authored-by: Linhart Lukáš <Lukas.Linhart@tescosw.cz>
This commit is contained in:
Lukáš Linhart 2024-09-20 10:39:11 +02:00 committed by GitHub
parent 89c8956523
commit dd2b93e8cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -9,11 +9,14 @@ const { CLI_VERSION } = require('../constants');
*/ */
function makeAxiosInstance() { function makeAxiosInstance() {
/** @type {axios.AxiosInstance} */ /** @type {axios.AxiosInstance} */
const instance = axios.create(); const instance = axios.create({
headers: {
"User-Agent": `bruno-runtime/${CLI_VERSION}`
}
});
instance.interceptors.request.use((config) => { instance.interceptors.request.use((config) => {
config.headers['request-start-time'] = Date.now(); config.headers['request-start-time'] = Date.now();
config.headers['user-agent'] = `bruno-runtime/${CLI_VERSION}`;
return config; return config;
}); });

View File

@ -7,6 +7,7 @@ const electronApp = require("electron");
const LOCAL_IPV6 = '::1'; const LOCAL_IPV6 = '::1';
const LOCAL_IPV4 = '127.0.0.1'; const LOCAL_IPV4 = '127.0.0.1';
const LOCALHOST = 'localhost'; const LOCALHOST = 'localhost';
const version = electronApp?.app?.getVersion()?.substring(1) ?? "";
const getTld = (hostname) => { const getTld = (hostname) => {
if (!hostname) { if (!hostname) {
@ -66,9 +67,11 @@ function makeAxiosInstance() {
}, this); }, this);
return data; 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) => { instance.interceptors.request.use(async (config) => {
const url = URL.parse(config.url); const url = URL.parse(config.url);
@ -88,7 +91,6 @@ function makeAxiosInstance() {
} }
config.headers['request-start-time'] = Date.now(); config.headers['request-start-time'] = Date.now();
config.headers['user-agent'] = `bruno-runtime/${version}`;
return config; return config;
}); });