Attempt to unify the disableRange/contentLength handling in the various network streams

First of all, note how in both `fetch_stream.js` and `node_stream.js` we always overwrite the `this._contentLength` property even when the response headers doesn't actually contain any (valid) length information. This could thus result in the `length` parameter, as passed to the network stream, being completely ignored despite having no better information available.
Secondly, in `node_stream.js` the `this._isRangeSupported` property wasn't always updated correctly based on the response headers.
This commit is contained in:
Jonas Jenwald 2018-02-09 13:39:38 +01:00
parent 25293628ff
commit ad06979cca
4 changed files with 10 additions and 13 deletions

View File

@ -74,14 +74,14 @@ class PDFFetchStreamReader {
this._withCredentials = source.withCredentials; this._withCredentials = source.withCredentials;
this._contentLength = source.length; this._contentLength = source.length;
this._headersCapability = createPromiseCapability(); this._headersCapability = createPromiseCapability();
this._disableRange = source.disableRange; this._disableRange = source.disableRange || false;
this._rangeChunkSize = source.rangeChunkSize; this._rangeChunkSize = source.rangeChunkSize;
if (!this._rangeChunkSize && !this._disableRange) { if (!this._rangeChunkSize && !this._disableRange) {
this._disableRange = true; this._disableRange = true;
} }
this._isRangeSupported = !source.disableRange;
this._isStreamingSupported = !source.disableStream; this._isStreamingSupported = !source.disableStream;
this._isRangeSupported = !source.disableRange;
this._headers = new Headers(); this._headers = new Headers();
for (let property in this._stream.httpHeaders) { for (let property in this._stream.httpHeaders) {
@ -112,8 +112,9 @@ class PDFFetchStreamReader {
disableRange: this._disableRange, disableRange: this._disableRange,
}); });
this._contentLength = suggestedLength;
this._isRangeSupported = allowRangeRequests; this._isRangeSupported = allowRangeRequests;
// Setting right content length.
this._contentLength = suggestedLength || this._contentLength;
this._filename = extractFilenameFromHeader(getResponseHeader); this._filename = extractFilenameFromHeader(getResponseHeader);

View File

@ -355,7 +355,6 @@ PDFNetworkStreamFullRequestReader.prototype = {
const getResponseHeader = (name) => { const getResponseHeader = (name) => {
return fullRequestXhr.getResponseHeader(name); return fullRequestXhr.getResponseHeader(name);
}; };
let { allowRangeRequests, suggestedLength, } = let { allowRangeRequests, suggestedLength, } =
validateRangeRequestCapabilities({ validateRangeRequestCapabilities({
getResponseHeader, getResponseHeader,
@ -364,12 +363,11 @@ PDFNetworkStreamFullRequestReader.prototype = {
disableRange: this._disableRange, disableRange: this._disableRange,
}); });
// Setting right content length.
this._contentLength = suggestedLength || this._contentLength;
if (allowRangeRequests) { if (allowRangeRequests) {
this._isRangeSupported = true; this._isRangeSupported = true;
} }
// Setting right content length.
this._contentLength = suggestedLength || this._contentLength;
this._filename = extractFilenameFromHeader(getResponseHeader); this._filename = extractFilenameFromHeader(getResponseHeader);

View File

@ -304,11 +304,9 @@ class PDFNodeStreamFullReader extends BaseFullReader {
disableRange: this._disableRange, disableRange: this._disableRange,
}); });
if (allowRangeRequests) { this._isRangeSupported = allowRangeRequests;
this._isRangeSupported = true;
}
// Setting right content length. // Setting right content length.
this._contentLength = suggestedLength; this._contentLength = suggestedLength || this._contentLength;
this._filename = extractFilenameFromHeader(getResponseHeader); this._filename = extractFilenameFromHeader(getResponseHeader);
}; };

View File

@ -28,8 +28,8 @@ var PDFDataTransportStream = (function PDFDataTransportStreamClosure() {
} }
this._pdfDataRangeTransport = pdfDataRangeTransport; this._pdfDataRangeTransport = pdfDataRangeTransport;
this._isRangeSupported = !(params.disableRange); this._isStreamingSupported = !params.disableStream;
this._isStreamingSupported = !(params.disableStream); this._isRangeSupported = !params.disableRange;
this._contentLength = params.length; this._contentLength = params.length;
this._fullRequestReader = null; this._fullRequestReader = null;