hypothesis / hypothesis/via

Avoid an extra network round trip when proxying PDFs

Open
#481 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
29
Forks
13
PR merge metrics
No merged PRs in 30d

Description

When a URL like `https://via.hypothes.is/https://example.com/foo.pdf` calls the [`proxy()` view](https://github.com/hypothesis/via3/blob/9b4f19b26458088b819cf4cae7936cbe125dfd0f/via/views/proxy.py#L7-L22), the view:

1. Determines whether `https://example.com/foo.pdf` is HTML or PDF (by making a `GET` request to `https://example.com/foo.pdf` and looking at the `Content-Type`)
2. Renders an `` whose `src` is either `https://via.hypothes.is/pdf?url=https://example.com/foo.pdf` (which goes to the [`view_pdf()` view](https://github.com/hypothesis/via3/blob/9b4f19b26458088b819cf4cae7936cbe125dfd0f/via/views/view_pdf.py#L13-L41)) or `https://viahtml.hypothes.is/proxy/https://example.com/foo.pdf` depending on whether `https://example.com/foo.pdf` is a PDF or not

This causes the browser to make an extra network round trip to get the `<iframe>`'s `src` URL.

In the case of PDFs this extra network round trip could be avoided: the `proxy()` view could just return the PDF.js response (as would be returned by the `view_pdf()` view) directly.

In the case of HTML the `proxy()` view does still need to return an `<iframe>` since HTML is handled by a separate app.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.