Skip to content

Commit e8074a9

Browse files
committed
fix: some servers do not accept our overwriting of user-agent
1 parent ae0a074 commit e8074a9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

worker/src/task/axios.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ import type { LogFunctions } from '@data-fair/lib-common-types/processings.js'
99
* Create an Axios instance.
1010
*/
1111
export const getAxiosInstance = (processing: Processing, log: LogFunctions) => {
12-
const headers: Record<string, string> = {
13-
'x-apiKey': config.dataFairAPIKey
12+
const privateHeaders: Record<string, string> = {
13+
'x-apiKey': config.dataFairAPIKey,
14+
// we used to specify User-Agent for all requests, but us creates problems with some external servers
15+
'User-Agent': `@data-fair/processings (${processing.plugin})`
1416
}
1517
if (config.dataFairAdminMode) {
1618
const account = { ...processing.owner }
1719
if (account.name) account.name = encodeURIComponent(account.name)
1820
if (account.departmentName) account.departmentName = encodeURIComponent(account.departmentName)
19-
headers['x-account'] = JSON.stringify(account)
21+
privateHeaders['x-account'] = JSON.stringify(account)
2022
}
21-
headers['x-processing'] = JSON.stringify({ _id: processing._id, title: encodeURIComponent(processing.title) })
23+
privateHeaders['x-processing'] = JSON.stringify({ _id: processing._id, title: encodeURIComponent(processing.title) })
2224

2325
const axiosInstance = axios.create({
2426
// this is necessary to prevent excessive memory usage during large file uploads, see https://github.com/axios/axios/issues/1045
@@ -35,8 +37,7 @@ export const getAxiosInstance = (processing: Processing, log: LogFunctions) => {
3537
else cfg.url = config.dataFairUrl + '/' + cfg.url
3638
}
3739
const isDataFairUrl = cfg.url.startsWith(config.dataFairUrl)
38-
if (isDataFairUrl) Object.assign(cfg.headers, headers)
39-
cfg.headers['User-Agent'] = cfg.headers['User-Agent'] ?? `@data-fair/processings (${processing.plugin})`
40+
if (isDataFairUrl) Object.assign(cfg.headers, privateHeaders)
4041

4142
// use private data fair url if specified to prevent leaving internal infrastructure
4243
// except from GET requests so that they still appear in metrics

0 commit comments

Comments
 (0)