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

Incorrect content-length header in reply to HEAD request when chunked transfer enconding is used #747

Closed
mdickopp opened this issue Feb 6, 2022 · 0 comments · Fixed by #755
Labels
A-axum C-bug Category: This is a bug.

Comments

@mdickopp
Copy link

mdickopp commented Feb 6, 2022

Bug Report

This is a followup to #730. Unfortunately, I found a case in which it still does not work correctly.

Version

axum main branch, commit 16ee83a

Platform

Debian Linux 12 (“bookworm”)
Linux feynman 5.15.0-3-amd64 #1 SMP Debian 5.15.15-1 (2022-01-18) x86_64 GNU/Linux
rustc 1.58.1 (db9d1b20b 2022-01-20)

Description

The content-length header in the reply to a simple HEAD request is set to 0 if the corresponding GET request uses transfer-encoding: chunked.

Steps to reproduce

Run the example program (which uses tower-http v0.2.1):

use axum::{routing::get, Router};
use tower_http::compression::{predicate::SizeAbove, CompressionLayer};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(|| async { "Hello, World!" }))
        .layer(CompressionLayer::new().compress_when(SizeAbove::new(0)));
    axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
        .serve(app.into_make_service())
        .await
        .unwrap();
}

Send a HTTP/1.1 HEAD request for /. Set the accept-encoding request header to gzip. I used the the following command on the Linux command line:

printf 'HEAD / HTTP/1.1\r\naccept-encoding: gzip\r\n\r\n' | nc 127.0.0.1 3000

Observed behavior

The output contains the line:

content-length: 0

Expected behavior

The output contains no content-length header.

Note the response to the corresponding GET request uses chunked transfer encoding. Its headers look like this:

HTTP/1.1 200 OK
content-type: text/plain; charset=utf-8
content-encoding: gzip
transfer-encoding: chunked
date: Sun, 06 Feb 2022 16:03:44 GMT
@davidpdrsn davidpdrsn added A-axum C-bug Category: This is a bug. labels Feb 6, 2022
davidpdrsn added a commit that referenced this issue Feb 14, 2022
…iddleware (#755)

* Fix getting `content-length` for `chunked` responses

Fixes #747

* changelog

* Fix `cargo deny bans`

#753 will fix things properly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-axum C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants