Skip to content

Commit

Permalink
lib: improve Accept Language header options
Browse files Browse the repository at this point in the history
  • Loading branch information
iparamonau committed Feb 13, 2025
1 parent 2679ae4 commit 33dd1a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 0 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@

FB_USER_AGENT: 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)',

ACCEPT_LANGUAGE_SUFFIX: ';q=0.9,en;q=0.7,*;q=0.5',

SKIP_IFRAMELY_RENDERS: false,
DEFAULT_ASPECT_RATIO: 16 / 9,
DOC_ASPECT_RATIO: 8.5 / 11,
Expand Down
11 changes: 8 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,15 @@ export function prepareRequestOptions(request_options, options) {
}
}

var lang = options && options.getProviderOptions && options.getProviderOptions('locale', 'en-US') || 'en-US';
if (lang && !disable_language) {
var lang = options?.getProviderOptions && options.getProviderOptions('locale') || '';
if (!disable_language) {
request_options.headers = request_options.headers || {};
request_options.headers['Accept-Language'] = lang.replace('_', '-') + CONFIG.ACCEPT_LANGUAGE_SUFFIX;
request_options.headers['Accept-Language'] =
lang /* !== '' */
? lang.replace('_', '-')
+ (/\-/.test(lang) ? `,${lang.replace(/\-.*$/, '')};q=0.9` : '')
+ ',en;q=0.7,*;q=0.5'
: 'en,*';
}

prepareEncodedUri(request_options, 'uri');
Expand Down

0 comments on commit 33dd1a5

Please sign in to comment.