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

feat(ext/http): auto-compression of fixed response bodies #13769

Merged
merged 9 commits into from
Mar 4, 2022

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Feb 24, 2022

Work in progress from a pairing session between myself and @ry

Inspired by previous work of @satyarohith on Deno Deploy.

@kitsonk kitsonk changed the title [WIP] automatic http response compression feat(ext/web): auto-compression of fixed response bodies Mar 3, 2022
@kitsonk kitsonk marked this pull request as ready for review March 3, 2022 04:21
@kitsonk kitsonk requested review from ry and satyarohith March 3, 2022 04:21
ext/http/lib.rs Outdated Show resolved Hide resolved
ext/http/lib.rs Outdated Show resolved Hide resolved
ext/http/lib.rs Outdated Show resolved Hide resolved
ext/http/lib.rs Outdated Show resolved Hide resolved
ext/http/lib.rs Outdated Show resolved Hide resolved
ext/http/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! @kitsonk what do you think about adding an option to disable this behaviour to a Deno.serveHttp options bag?

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also do we need to have special handling for Range?

ext/http/lib.rs Show resolved Hide resolved
@kitsonk
Copy link
Contributor Author

kitsonk commented Mar 4, 2022

This is looking great! @kitsonk what do you think about adding an option to disable this behaviour to a Deno.serveHttp options bag?

I thought about it when I paired with @ry and he argued against it. It does add complexity to it. Is there a compelling case where someone would want to disable it, other than "because they can"? Doesn't setting Cache-Control: no-transform effectively provide that functionality without adding to the API surface? That is how CFW supports disabling it.

@lucacasonato
Copy link
Member

I could imagine that one has an nginx in front of Deno that is responsible for on the fly encoding. In that case you want Deno to leave the responses as "pure" as possible. I don't think we per-se need to add this for the PR to land, but I think it would be useful to give users an opt-out. The implementation complexity seems rather trivial.

@kitsonk
Copy link
Contributor Author

kitsonk commented Mar 4, 2022

Also do we need to have special handling for Range?

Actually, after doing a bit of research, if a Content-Range header is present in the response, we should disable automatic compression, as the user HTTP server has processed a range request, with the range being based off the uncompressed range headers it negotiated.

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@satyarohith PTAL too


// Data obtained from https://github.com/jshttp/mime-db/blob/fa5e4ef3cc8907ec3c5ec5b85af0c63d7059a5cd/db.json
// Important! Keep this list sorted alphabetically.
const CONTENT_TYPES: &[&str] = &[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there are some new additions to https://github.com/jshttp/mime-db/blob/master/db.json; we might want to update the list.

feel free to skip it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's skip it for now, as they are very likely very esoteric media types that aren't widely used.

Longer term, someone should either find an efficient way to statically include the JSON in, or generate the code statically from the JSON file.

kitsonk and others added 2 commits March 4, 2022 15:37
Co-authored-by: Satya Rohith <[email protected]>
Co-authored-by: Satya Rohith <[email protected]>
Copy link
Member

@satyarohith satyarohith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Thanks for working on it! :)

@kitsonk kitsonk changed the title feat(ext/web): auto-compression of fixed response bodies feat(ext/http): auto-compression of fixed response bodies Mar 4, 2022
@kitsonk kitsonk merged commit d1db500 into denoland:main Mar 4, 2022
@kitsonk kitsonk deleted the feat_http_compression branch March 4, 2022 05:04
@kt3k kt3k mentioned this pull request Mar 10, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants