Merge pull request #8845 from yurydelendik/fix-autofetch
Fixes autofetch and firefox nightly fetch streams
This commit is contained in:
commit
2656825432
@ -13,7 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { assert, createPromiseCapability } from '../shared/util';
|
import {
|
||||||
|
AbortException, assert, createPromiseCapability
|
||||||
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
createResponseStatusError, validateRangeRequestCapabilities,
|
createResponseStatusError, validateRangeRequestCapabilities,
|
||||||
validateResponseStatus
|
validateResponseStatus
|
||||||
@ -95,8 +97,8 @@ class PDFFetchStreamReader {
|
|||||||
if (!validateResponseStatus(response.status, this._stream.isHttp)) {
|
if (!validateResponseStatus(response.status, this._stream.isHttp)) {
|
||||||
throw createResponseStatusError(response.status, url);
|
throw createResponseStatusError(response.status, url);
|
||||||
}
|
}
|
||||||
this._headersCapability.resolve();
|
|
||||||
this._reader = response.body.getReader();
|
this._reader = response.body.getReader();
|
||||||
|
this._headersCapability.resolve();
|
||||||
|
|
||||||
let { allowRangeRequests, suggestedLength, } =
|
let { allowRangeRequests, suggestedLength, } =
|
||||||
validateRangeRequestCapabilities({
|
validateRangeRequestCapabilities({
|
||||||
@ -110,6 +112,12 @@ class PDFFetchStreamReader {
|
|||||||
|
|
||||||
this._contentLength = suggestedLength;
|
this._contentLength = suggestedLength;
|
||||||
this._isRangeSupported = allowRangeRequests;
|
this._isRangeSupported = allowRangeRequests;
|
||||||
|
|
||||||
|
// We need to stop reading when range is supported and streaming is
|
||||||
|
// disabled.
|
||||||
|
if (!this._isStreamingSupported && this._isRangeSupported) {
|
||||||
|
this.cancel(new AbortException('streaming is disabled'));
|
||||||
|
}
|
||||||
}).catch(this._headersCapability.reject);
|
}).catch(this._headersCapability.reject);
|
||||||
|
|
||||||
this.onProgress = null;
|
this.onProgress = null;
|
||||||
|
@ -19,7 +19,9 @@ let http = __non_webpack_require__('http');
|
|||||||
let https = __non_webpack_require__('https');
|
let https = __non_webpack_require__('https');
|
||||||
let url = __non_webpack_require__('url');
|
let url = __non_webpack_require__('url');
|
||||||
|
|
||||||
import { assert, createPromiseCapability } from '../shared/util';
|
import {
|
||||||
|
AbortException, assert, createPromiseCapability
|
||||||
|
} from '../shared/util';
|
||||||
import { validateRangeRequestCapabilities } from './network_utils';
|
import { validateRangeRequestCapabilities } from './network_utils';
|
||||||
|
|
||||||
class PDFNodeStream {
|
class PDFNodeStream {
|
||||||
@ -165,6 +167,12 @@ class BaseFullReader {
|
|||||||
this._error(reason);
|
this._error(reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// We need to stop reading when range is supported and streaming is
|
||||||
|
// disabled.
|
||||||
|
if (!this._isStreamingSupported && this._isRangeSupported) {
|
||||||
|
this._error(new AbortException('streaming is disabled'));
|
||||||
|
}
|
||||||
|
|
||||||
// Destroy ReadableStream if already in errored state.
|
// Destroy ReadableStream if already in errored state.
|
||||||
if (this._errored) {
|
if (this._errored) {
|
||||||
this._readableStream.destroy(this._reason);
|
this._readableStream.destroy(this._reason);
|
||||||
@ -353,8 +361,6 @@ class PDFNodeStreamFsFullReader extends BaseFullReader {
|
|||||||
constructor(stream) {
|
constructor(stream) {
|
||||||
super(stream);
|
super(stream);
|
||||||
|
|
||||||
this._setReadableStream(fs.createReadStream(this._url.path));
|
|
||||||
|
|
||||||
fs.lstat(this._url.path, (error, stat) => {
|
fs.lstat(this._url.path, (error, stat) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this._errored = true;
|
this._errored = true;
|
||||||
@ -364,6 +370,8 @@ class PDFNodeStreamFsFullReader extends BaseFullReader {
|
|||||||
}
|
}
|
||||||
// Setting right content length.
|
// Setting right content length.
|
||||||
this._contentLength = stat.size;
|
this._contentLength = stat.size;
|
||||||
|
|
||||||
|
this._setReadableStream(fs.createReadStream(this._url.path));
|
||||||
this._headersCapability.resolve();
|
this._headersCapability.resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,8 @@ if (typeof PDFJSDev === 'undefined' ||
|
|||||||
if (pdfjsSharedUtil.isNodeJS()) {
|
if (pdfjsSharedUtil.isNodeJS()) {
|
||||||
var PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
|
var PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
|
||||||
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFNodeStream);
|
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFNodeStream);
|
||||||
} else if (typeof Response !== 'undefined' && 'body' in Response.prototype) {
|
} else if (typeof Response !== 'undefined' && 'body' in Response.prototype &&
|
||||||
|
typeof ReadableStream !== 'undefined') {
|
||||||
var PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
|
var PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
|
||||||
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFFetchStream);
|
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFFetchStream);
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,7 +80,8 @@ function initializePDFJS(callback) {
|
|||||||
var PDFFetchStream = modules[3].PDFFetchStream;
|
var PDFFetchStream = modules[3].PDFFetchStream;
|
||||||
|
|
||||||
// Set network stream class for unit tests.
|
// Set network stream class for unit tests.
|
||||||
if (typeof Response !== 'undefined' && 'body' in Response.prototype) {
|
if (typeof Response !== 'undefined' && 'body' in Response.prototype &&
|
||||||
|
typeof ReadableStream !== 'undefined') {
|
||||||
displayApi.setPDFNetworkStreamClass(PDFFetchStream);
|
displayApi.setPDFNetworkStreamClass(PDFFetchStream);
|
||||||
} else {
|
} else {
|
||||||
displayApi.setPDFNetworkStreamClass(PDFNetworkStream);
|
displayApi.setPDFNetworkStreamClass(PDFNetworkStream);
|
||||||
|
Loading…
Reference in New Issue
Block a user