question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support gzip in range request / Explicitly set accept-encoding: identity

See original GitHub issue

I’m using react-pdf, which in turn uses pdf.js (awesome library, guys!), for a web application that shows open governmental meeting documents (demo). I noticed that for large PDF files, loading takes a while, and it seems like pdf.js downloads the entire file before rendering the first page.

The docs mention that PDF.js fetches only the necessary data, if the server supports Content-Range header / Range requests.

The server (Google Cloud Storage) seems to support ranges (example file).

GET https://storage.googleapis.com/ori-static/api.notubiz.nl/document/6131301 HTTP/1.1
Range: bytes=0-1999

The maintainer of react-pdf told me it should work If we simply pass a URL to pdfjs.getDocument, but it does not.

Is it true that getDocument should use the Range header if only a URL is passed?

Am I missing something? Should I manually create a PDFDataRangeTransport? Thanks in advance for your time!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timvandermeijcommented, Aug 5, 2019
0reactions
Snuffleupaguscommented, Feb 2, 2020

According to the specifications, see e.g. the XMLHttpRequest specification which links to the relevant part of the Fetch specification, the Accept-Encoding cannot be set (other than the by browser itself); see also https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name Hence it won’t be possible to add Accept-Encoding: identity to the network requests made by the PDF.js library.

With regards to adding support for gzip in the various stream implementations, that would risk adding a lot of additional complexity to the relevant code (not to mention the time/effort required to implement/review/test something like that). Furthermore, the problem in this issue seem to be limited to a particular server rather than be a widespread issue.

All-in-all, it seems that WONTFIX probably is the appropriate resolution for this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accept-Encoding - HTTP - MDN Web Docs
The Accept-Encoding request HTTP header indicates the content encoding (usually a compression algorithm) that the client can understand.
Read more >
Send uncompressed if the Accept-Encoding does not ...
So, yes, you can reply with identity on Accept-encoding: gzip, deflate for instance, but not on Accept-encoding: gzip, deflate, identity ...
Read more >
Accept-Encoding - HTTP
The Accept-Encoding request HTTP header advertises which content encoding, usually a compression algorithm, the client is able to understand.
Read more >
Response compression in ASP.NET Core
Accept-Encoding header values, Middleware Supported, Description ... if the Gzip compression provider is the only provider explicitly added, ...
Read more >
Advanced Usage — Requests 1.2.3 documentation
Session() s.get('http://httpbin.org/cookies/set/sessioncookie/123456789') r ... r.request.headers {'Accept-Encoding': 'identity, deflate, compress, gzip', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found