Skip to content

Commit

Permalink
Correctly validate the response status for non-HTTP fetch requests (P…
Browse files Browse the repository at this point in the history
…R 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".`
  • Loading branch information
Snuffleupagus committed Sep 5, 2017
1 parent cd25a51 commit 41415ba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/display/fetch_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions src/display/network_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 41415ba

Please sign in to comment.