diff --git a/src/display/display_utils.js b/src/display/display_utils.js index 36b6850de601f2..da7b5b370a29d0 100644 --- a/src/display/display_utils.js +++ b/src/display/display_utils.js @@ -486,5 +486,6 @@ export { DOMSVGFactory, StatTimer, DummyStatTimer, + isValidFetchUrl, loadScript, }; diff --git a/src/pdf.js b/src/pdf.js index 10c463df72659e..bd024d99264d80 100644 --- a/src/pdf.js +++ b/src/pdf.js @@ -38,14 +38,17 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => { return new PDFNodeStream(params); }); - } else if (isFetchSupported()) { - let PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream; - pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => { - return new PDFFetchStream(params); - }); } else { let PDFNetworkStream = require('./display/network.js').PDFNetworkStream; + let PDFFetchStream; + if (isFetchSupported()) { + PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream; + } pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => { + if (PDFFetchStream && + pdfjsDisplayDisplayUtils.isValidFetchUrl(params.url)) { + return new PDFFetchStream(params); + } return new PDFNetworkStream(params); }); } @@ -70,8 +73,8 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream; } pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => { - if (PDFFetchStream && /^https?:/i.test(params.url)) { - // "fetch" is only supported for http(s), not file/ftp. + if (PDFFetchStream && + pdfjsDisplayDisplayUtils.isValidFetchUrl(params.url)) { return new PDFFetchStream(params); } return new PDFNetworkStream(params);