diff --git a/lib/fetch.js b/lib/fetch.js index a429cfc6f..d17cce1cb 100644 --- a/lib/fetch.js +++ b/lib/fetch.js @@ -44,7 +44,8 @@ export function skipLoggingFetchError(error) { || error?.code === 'ERR_STREAM_PREMATURE_CLOSE' || error?.code === 'ERR_HTTP2_STREAM_ERROR' || error?.code === 'ERR_HTTP2_SESSION_ERROR' - || error?.code === 'Z_DATA_ERROR'; + || error?.code === 'Z_DATA_ERROR' + || error?.code === 'Z_BUF_ERROR'; } function doFetch(fetch_func, h1_fetch_func, options) { diff --git a/lib/utils.js b/lib/utils.js index 361a7aa78..8a50350e4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -115,7 +115,16 @@ export function prepareRequestOptions(request_options, options) { setPrerender(enable_domain_prerender); } + // Make empty headers by default for all cases. request_options.headers = request_options.headers || {}; + + // Put forward headers. + const forward_headers = options?.getProviderOptions && options.getProviderOptions('app.http_forward_headers'); + if (forward_headers && typeof forward_headers === 'object' && !Array.isArray(forward_headers)) { + for (const [key, value] of Object.entries(forward_headers)) { + request_options.headers[key] = value; + } + } if (CONFIG.PROXY || options?.proxy) { @@ -135,7 +144,6 @@ export function prepareRequestOptions(request_options, options) { request_options.headers['User-Agent'] = proxy.user_agent; } if (proxy.headers) { - request_options.headers = request_options.headers || {}; Object.assign(request_options.headers, proxy.headers) } if (proxy.request_options) { @@ -182,7 +190,6 @@ export function prepareRequestOptions(request_options, options) { var lang = options?.getProviderOptions && options.getProviderOptions('locale') || ''; if (!disable_language) { - request_options.headers = request_options.headers || {}; request_options.headers['Accept-Language'] = lang /* !== '' */ ? lang.replace('_', '-') @@ -195,7 +202,10 @@ export function prepareRequestOptions(request_options, options) { setCookieFromJar(uri, request_options.headers, options?.jar) - if ((options?.sig || request_sig) && options?.getSigHeaders) { + // Has header begining from "Signature". + const prevent_sig = Object.keys(request_options.headers).some(key => /^signature/i.test(key)); + + if (!prevent_sig && (options?.sig || request_sig) && options?.getSigHeaders) { try { options.getSigHeaders(original_uri, function(error, headers) { if (error) { @@ -203,7 +213,6 @@ export function prepareRequestOptions(request_options, options) { console.error('getSigHeaders error', error); resolve(request_options); } else { - request_options.headers = request_options.headers || {}; Object.assign(request_options.headers, headers); resolve(request_options); }