Assert that PDFFetchStream is only used with HTTP(S) URLs

Note how `getDocument` checks the protocol, via the `isValidFetchUrl` helper, before attempting to use the `PDFFetchStream` implementation.
This commit is contained in:
Jonas Jenwald 2026-02-01 18:21:27 +01:00
parent 586e85888b
commit 6509fdb1d6

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { AbortException, warn } from "../shared/util.js"; import { AbortException, assert, warn } from "../shared/util.js";
import { import {
BasePDFStream, BasePDFStream,
BasePDFStreamRangeReader, BasePDFStreamRangeReader,
@ -69,8 +69,11 @@ class PDFFetchStream extends BasePDFStream {
super(source, PDFFetchStreamReader, PDFFetchStreamRangeReader); super(source, PDFFetchStreamReader, PDFFetchStreamRangeReader);
const { httpHeaders, url } = source; const { httpHeaders, url } = source;
this.isHttp = /https?:/.test(url.protocol); assert(
this.headers = createHeaders(this.isHttp, httpHeaders); /https?:/.test(url.protocol),
"PDFFetchStream only supports http(s):// URLs."
);
this.headers = createHeaders(/* isHttp = */ true, httpHeaders);
} }
} }
@ -108,7 +111,7 @@ class PDFFetchStreamReader extends BasePDFStreamReader {
const { allowRangeRequests, suggestedLength } = const { allowRangeRequests, suggestedLength } =
validateRangeRequestCapabilities({ validateRangeRequestCapabilities({
responseHeaders, responseHeaders,
isHttp: stream.isHttp, isHttp: true,
rangeChunkSize, rangeChunkSize,
disableRange, disableRange,
}); });