Merge pull request #9447 from Rob--W/crx-fetch-expose-headers
Expose some headers to fetch requests from the PDF.js Chrome extension
This commit is contained in:
commit
43f1f96b10
@ -117,8 +117,17 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
|
||||
delete g_referrers[tabId][frameId];
|
||||
}
|
||||
chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
|
||||
chrome.webRequest.onHeadersReceived.removeListener(exposeOnHeadersReceived);
|
||||
});
|
||||
|
||||
// Expose some response headers for fetch API calls from PDF.js;
|
||||
// This is a work-around for https://crbug.com/784528
|
||||
chrome.webRequest.onHeadersReceived.addListener(exposeOnHeadersReceived, {
|
||||
urls: ['https://*/*'],
|
||||
types: ['xmlhttprequest'],
|
||||
tabId: tabId,
|
||||
}, ['blocking', 'responseHeaders']);
|
||||
|
||||
function onBeforeSendHeaders(details) {
|
||||
if (details.frameId !== frameId) {
|
||||
return;
|
||||
@ -137,4 +146,22 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
|
||||
refererHeader.value = referer;
|
||||
return { requestHeaders: headers, };
|
||||
}
|
||||
|
||||
function exposeOnHeadersReceived(details) {
|
||||
if (details.frameId !== frameId) {
|
||||
return;
|
||||
}
|
||||
var headers = details.responseHeaders;
|
||||
var aceh = getHeaderFromHeaders(headers, 'access-control-expose-headers');
|
||||
// List of headers that PDF.js uses in src/display/network_utils.js
|
||||
var acehValue =
|
||||
'accept-ranges,content-encoding,content-length,content-disposition';
|
||||
if (aceh) {
|
||||
aceh.value += ',' + acehValue;
|
||||
} else {
|
||||
aceh = { name: 'Access-Control-Expose-Headers', value: acehValue, };
|
||||
headers.push(aceh);
|
||||
}
|
||||
return { responseHeaders: headers, };
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user