Skip to content

Commit 5e5afc1

Browse files
committed
fix user agent assign priority
1 parent 8037430 commit 5e5afc1

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

lib/utils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ export function prepareRequestOptions(request_options, options) {
111111
}
112112

113113
request_options.headers = request_options.headers || {};
114-
request_options.headers['User-Agent'] = options?.user_agent || CONFIG.USER_AGENT;
115-
114+
116115
if (CONFIG.PROXY || options?.proxy) {
117116

118117
var proxy = options?.proxy || getCustomProxyForUri(uri, options);
@@ -155,6 +154,14 @@ export function prepareRequestOptions(request_options, options) {
155154
}
156155
}
157156

157+
if (options?.user_agent) {
158+
// Let `options.user_agent` be prioritized over `proxy.user_agent`.
159+
request_options.headers['User-Agent'] = options?.user_agent;
160+
} else if (!request_options.headers['User-Agent']) {
161+
// ...otherwise use default user agent.
162+
request_options.headers['User-Agent'] = CONFIG.USER_AGENT;
163+
}
164+
158165
// Add user agent extension to default agent if avaliable.
159166
if (options?.getProviderOptions
160167
&& (options.getProviderOptions('app.name') || options.getProviderOptions('app.ua_extension'))

0 commit comments

Comments
 (0)