@@ -110,6 +110,9 @@ export function prepareRequestOptions(request_options, options) {
110110 setPrerender ( enable_domain_prerender ) ;
111111 }
112112
113+ request_options . headers = request_options . headers || { } ;
114+ request_options . headers [ 'User-Agent' ] = options . user_agent || CONFIG . USER_AGENT ;
115+
113116 if ( CONFIG . PROXY || ( options && options . proxy ) ) {
114117
115118 var proxy = ( options && options . proxy ) || getCustomProxyForUri ( uri , options ) ;
@@ -125,7 +128,6 @@ export function prepareRequestOptions(request_options, options) {
125128 request_options . uri = proxy . proxy_url . replace ( / { u r l } / , encodeURIComponent ( uri ) ) ;
126129 }
127130 if ( proxy . user_agent ) {
128- request_options . headers = request_options . headers || { } ;
129131 request_options . headers [ 'User-Agent' ] = proxy . user_agent ;
130132 }
131133 if ( proxy . headers ) {
@@ -153,17 +155,18 @@ export function prepareRequestOptions(request_options, options) {
153155 }
154156 }
155157
156- if ( options && options . getProviderOptions
158+ // Add user agent extension to default agent if avaliable.
159+ if ( options ?. getProviderOptions
157160 && ( options . getProviderOptions ( 'app.name' ) || options . getProviderOptions ( 'app.ua_extension' ) )
158161 && request_options . headers
159162 && request_options . headers [ 'User-Agent' ] === CONFIG . USER_AGENT ) {
160163
161164 var ext = options . getProviderOptions ( 'app.ua_extension' , options . getProviderOptions ( 'app.name' ) ) ;
162- if ( / ^ [ a - z A - Z 0 - 9 \. \s _ - ] + $ / . test ( ext ) && ext . length > 1 ) {
165+ if ( / ^ [ a - z A - Z 0 - 9 \. \s _ - ] + $ / . test ( ext ) && ext . length > 1 ) {
163166 ext = ext [ 0 ] . toUpperCase ( ) + ext . slice ( 1 )
164167 request_options . headers [ 'User-Agent' ] += ' ' + ext ;
165- }
166- }
168+ }
169+ }
167170
168171 var lang = options ?. getProviderOptions && options . getProviderOptions ( 'locale' ) || '' ;
169172 if ( ! disable_language ) {
@@ -244,7 +247,6 @@ export function prepareRequestOptions(request_options, options) {
244247 uri : url ,
245248 method : 'GET' ,
246249 headers : {
247- 'User-Agent' : options . user_agent || CONFIG . USER_AGENT ,
248250 'Accept' : '*/*'
249251 } ,
250252 timeout : options . timeout || CONFIG . RESPONSE_TIMEOUT ,
@@ -322,9 +324,6 @@ var getHead = function(url, options, callbacks) {
322324 // Reviewed.
323325 uri : url ,
324326 method : 'HEAD' ,
325- headers : {
326- 'User-Agent' : CONFIG . USER_AGENT
327- } ,
328327 timeout : options . timeout || CONFIG . RESPONSE_TIMEOUT ,
329328 redirect : redirect ,
330329 follow : follow
@@ -1278,9 +1277,6 @@ var getUriStatusPrivate = function(uri, options, cb) {
12781277 // Reviewed.
12791278 uri : uri ,
12801279 method : 'GET' ,
1281- headers : {
1282- 'User-Agent' : CONFIG . USER_AGENT
1283- } ,
12841280 timeout : options . timeout || CONFIG . RESPONSE_TIMEOUT ,
12851281 follow : CONFIG . MAX_REDIRECTS
12861282 } )
0 commit comments