Correctly validate the response status for non-HTTP fetch requests (PR 8768 follow-up)

It seems that the status check, for non-HTTP loads, causes the default viewer to *refuse* to open local PDF files.

***STR:***
 1. Make sure that fetch support is enabled in the browser. In Firefox Nightly, set `dom.streams.enabled = true` and `javascript.options.streams = true` in `about:config`.
 2. Open https://mozilla.github.io/pdf.js/web/viewer.html.
 3. Click on the "Open file" button, and open a new PDF file.

***ER:***
 A new PDF file should open in the viewer.

***AR:***
 The PDF file fails to open, with an error message of the following format:
`Message: Unexpected server response (200) while retrieving PDF "blob:https://mozilla.github.io/a4fc455f-bc05-45b5-b6aa-2ecff3cb45ce".`
This commit is contained in:
Jonas Jenwald 2017-09-02 11:57:15 +02:00
parent cd25a51abe
commit 41415ba0a2
2 changed files with 3 additions and 6 deletions

View File

@ -94,7 +94,7 @@ class PDFFetchStreamReader {
let url = this._stream.source.url;
fetch(url, createFetchOptions(this._headers, this._withCredentials)).
then((response) => {
if (!validateResponseStatus(response.status, this._stream.isHttp)) {
if (!validateResponseStatus(response.status)) {
throw createResponseStatusError(response.status, url);
}
this._reader = response.body.getReader();
@ -188,7 +188,7 @@ class PDFFetchStreamRangeReader {
let url = this._stream.source.url;
fetch(url, createFetchOptions(this._headers, this._withCredentials)).
then((response) => {
if (!validateResponseStatus(response.status, this._stream.isHttp)) {
if (!validateResponseStatus(response.status)) {
throw createResponseStatusError(response.status, url);
}
this._readCapability.resolve();

View File

@ -61,10 +61,7 @@ function createResponseStatusError(status, url) {
') while retrieving PDF "' + url + '".', status);
}
function validateResponseStatus(status, isHttp) {
if (!isHttp) {
return status === 0;
}
function validateResponseStatus(status) {
return status === 200 || status === 206;
}