Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test whether to use range-requests in pdf.js ? #11820

Closed
wideweide opened this issue Apr 17, 2020 · 1 comment
Closed

How to test whether to use range-requests in pdf.js ? #11820

wideweide opened this issue Apr 17, 2020 · 1 comment

Comments

@wideweide
Copy link

wideweide commented Apr 17, 2020

Steps to reproduce the problem:

  1. I created a servlet for download files from a java file server: head to reponse accept-ranges,support range in header...
  2. user pdf.js to show pdf: viewer.html?file=...download/fileid

What is the expected behavior? (add screenshot)
use range-requests

What went wrong? (add screenshot)
but just load the full file then display

So How to test whether to use range-requests in pdf.js ?

@Snuffleupagus
Copy link
Collaborator

So How to test whether to use range-requests in pdf.js ?

See

function validateRangeRequestCapabilities({
getResponseHeader,
isHttp,
rangeChunkSize,
disableRange,
}) {
assert(rangeChunkSize > 0, "Range chunk size must be larger than zero");
const returnValues = {
allowRangeRequests: false,
suggestedLength: undefined,
};
const length = parseInt(getResponseHeader("Content-Length"), 10);
if (!Number.isInteger(length)) {
return returnValues;
}
returnValues.suggestedLength = length;
if (length <= 2 * rangeChunkSize) {
// The file size is smaller than the size of two chunks, so it does not
// make any sense to abort the request and retry with a range request.
return returnValues;
}
if (disableRange || !isHttp) {
return returnValues;
}
if (getResponseHeader("Accept-Ranges") !== "bytes") {
return returnValues;
}
const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
if (contentEncoding !== "identity") {
return returnValues;
}
returnValues.allowRangeRequests = true;
return returnValues;
}

If that's not enough to answer your question, then please provide all of the information requested in https://github.com/mozilla/pdf.js/blob/master/.github/ISSUE_TEMPLATE.md since as-is this issue doesn't really seem actionable; please also see https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants