Skip to content

Commit

Permalink
Use Content-Range instead of Content-Length mozilla#5512
Browse files Browse the repository at this point in the history
Use Content-Range header instead of Content-Length when the
response has status code 206, to work around issue mozilla#5512,
which is caused by a bug in Chrome (since version 39):
https://code.google.com/p/chromium/issues/detail?id=442318
  • Loading branch information
Rob--W committed Jan 6, 2015
1 parent 6e66e30 commit c02b2cb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {

var length = fullRequestXhr.getResponseHeader('Content-Length');
length = parseInt(length, 10);
//#if (GENERIC || CHROME)
if (fullRequestXhr.status === 206) {
// Since Chrome 39, there exists a bug where cached responses are
// served with status code 206 for non-range requests.
// Content-Length does not specify the total size of the resource
// when the status code is 206 (see RFC 2616, section 14.16).
// In this case, extract the file size from the Content-Range
// header, which is defined to be "bytes start-end/length" for
// byte range requests.
// See https://github.com/mozilla/pdf.js/issues/5512 and
// https://code.google.com/p/chromium/issues/detail?id=442318
length = fullRequestXhr.getResponseHeader('Content-Range');
length = length && /bytes \d+-\d+\/(\d+)/.exec(length);
length = length && parseInt(length[1], 10);
}
//#endif
if (!isInt(length)) {
return;
}
Expand Down

0 comments on commit c02b2cb

Please sign in to comment.