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

Progressive rendering not working #9609

Closed
lucaong opened this issue Mar 28, 2018 · 5 comments
Closed

Progressive rendering not working #9609

lucaong opened this issue Mar 28, 2018 · 5 comments
Labels

Comments

@lucaong
Copy link

lucaong commented Mar 28, 2018

Attach (recommended) or Link to PDF file here:

Configuration:

  • Web browser and its version: Chrome 65.0.3325.181
  • Operating system and its version: Mac OSX 10.13.3
  • PDF.js version: 2.0.449
  • Is a browser extension: no

What is the expected behavior?

I have a linearized PDF, and a server returning accept-ranges: bytes. I expect the PDF to be progressively loaded/rendered, and to observe Range requests with 206 response codes, but instead no Range request is made, and the whole PDF is loaded and rendered in bulk.

I read a lot of other issues and responses related to Range requests, but I still cannot find what is wrong in my setup. CORS headers are OK, Accept-Ranges header is returned by the server, Range requests are supported (as tested with CURL).

Two specific things in my setup are:

  • accept-ranges is lower case (PDF is on Google Cloud Storage). But headers should be case insensitive.
  • The original request for the PDF responds with a 302 redirect to the actual file URL. Could this confuse PDFJS, as the redirect does not contain accept-ranges?

screen shot 2018-03-28 at 8 09 47 pm

As you can see, the Accept-Ranges header is properly returned:

screen shot 2018-03-28 at 8 10 18 pm

Any idea?

@Gabri-connect
Copy link

bump - Having same issue

@Snuffleupagus
Copy link
Collaborator

Unfortunately it's simply impossible for anyone to help with only a description/screen-shot of the problem, please 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 on the IRC channel -- keep in mind that just code snippets won't help us troubleshoot the problem.

@angel-langdon
Copy link

angel-langdon commented Jan 30, 2022

@timvandermeij @Snuffleupagus @lucaong Hi, I know what the problem is here.

Yesterday I was implementing Range Requests using FastAPI from Python. This framework uses Starlette under the hood and Starlette sends headers always lower-case (as the example).

This is causing to not work properly Range-requests due to case-sensitive headers implementation of PDF.js, could you please fix this?

According to RFC 7230 (HTTP/1.1):

Each header field consists of a case-insensitive field name
followed by a colon (":"), optional leading whitespace, the field
value, and optional trailing whitespace.

https://www.rfc-editor.org/rfc/rfc7230#section-3.2

Also, RFC 7540 (HTTP/2):

Just as in HTTP/1.x, header field names are strings of ASCII
characters that are compared in a case-insensitive fashion.

https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2

@kentingnguyen
Copy link

kentingnguyen commented Jun 30, 2022

bump - I'm also running into this issue with Java Spring with Apache tomcat, which also sends headers as lower-case.

The code that seems to check the response header is this, and I didn't see any modifications to the header casing before it goes into the function

https://github.com/mozilla/pdf.js/blob/master/src/display/network_utils.js

function validateRangeRequestCapabilities({
...

if (getResponseHeader("Accept-Ranges") !== "bytes") {
   return returnValues;
 }

However, based on this issue, I'm also seeing conflicting information on whether it works with lowercase or not.
#11174

Could we get a confirmation one way or another on whether lower-case headers don't work and should be supported according to the RFC specs?

@angel-langdon
Copy link

angel-langdon commented Jun 30, 2022

Could we get a confirmation one way or another on whether lower-case headers don't work and should be supported according to the RFC specs?

@kentingnguyen I can confirm you that lowercase headers do not make a difference. I was able to achieve progressive rendering by correctly implementing my backend logic

Related issue #14514

image

My backend implementation in Python using range requests, maybe you can translate it to Java
https://stackoverflow.com/a/71309270/12234006

Another related issue
wojtekmaj/react-pdf#419 (comment)

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

No branches or pull requests

6 participants