Skip to content

Don't include identity in Content-Encoding header #317

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

Merged
merged 3 commits into from
Jan 5, 2023

Conversation

Bobo1239
Copy link
Contributor

According to the spec identity should only be used for the Accept-Encoding header and not be included in Content-Encoding.

In practice this change fixes chunked video loading in Firefox when using ServeDir. (making seeking possible without downloading the whole video file)

According to the [spec][1] `identity` should only be used for the
Accept-Encoding header and not be included in Content-Encoding.

In practice this change fixes chunked video loading in Firefox when
using `ServeDir`. (making seeking possible without downloading the whole
video file)

[1]: https://httpwg.org/specs/rfc9110.html#field.content-encoding
Copy link
Collaborator

@Nehliin Nehliin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Do you have an example when this actually is set as an header value? I updated some of our tests to check if we return the encoding when serving uncompressed files and it doesn't look like we set the header value in the basic scenarios.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Bobo1239
Copy link
Contributor Author

Bobo1239 commented Jan 4, 2023

Thanks for the review. I've added a test which would've returned Content-Encoding: identity previously.

Also for posterity's sake: The original problem (video seeking) can be reproduced by using the simplest ServeDir example (see below) and navigating to a large video file in Firefox. In my case this was a 1.2GB .webm video. Without this PR seeking inside the video had a noticeable delay as the whole video would be downloaded and no range requests would be used. (not sure whether Firefox should do better here or not)

Code
use std::net::{Ipv4Addr, SocketAddr};

use axum::Server;
use tower::make::Shared;
use tower_http::services::ServeDir;

#[tokio::main]
async fn main() {
    let addr = SocketAddr::from((Ipv4Addr::UNSPECIFIED, 3000));

    let service = ServeDir::new(".");
    Server::bind(&addr)
        .serve(Shared::new(service))
        .await
        .expect("server error");
}

Copy link
Collaborator

@Nehliin Nehliin left a comment

Choose a reason for hiding this comment

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

Thanks!

@davidpdrsn davidpdrsn merged commit 06b21d8 into tower-rs:master Jan 5, 2023
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