-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Content-Length
is not set when using compression
#3035
Comments
@SabrinaJewson pinging since you made the patch regarding content length and layers. If you have any idea how to make this work, that would be appreciated, if not, I'll try to dig into it when I get some time. |
I thought I had read that
Actually looking at previous tower-http issues, I found that So maybe this actually fixed a bug for crates.io? It seems weird, do HTTP clients not raise an error when they receive fewer body bytes than the |
There never was a scenario when less bytes were sent than declared in the content length header. When compression occurred, it used chunked encoding. As far as I can tell the only difference is when there is a compression layer that does nothing because of a missing accept encoding header in the request. In that case, we used to send the content length, but we do not anymore. |
Oh, I see. Interesting! That sounds like it may be fixable by adding a size hint to tower-http's compression body if it's in no-compression mode? |
I agree with jplatte, so I opened tower-rs/tower-http#531 |
So the fix for anyone looking for the original behavior should be to just wait for new I'll probably try this with crates.io when I get some time to see if there are any other layers there that have similar effect and also need the size hint. |
New version of |
rust-lang/crates.io#9994 updated crates.io to the new |
Bug Report
Version
0.7.9 and main
Platform
All
Crates
axum
Description
When the following code is run and a request is made against
/
with noaccept-encoding
header, we used to send a response withcontent-length
but we're instead sendingtransfer-encoding: chunked
now. If compression is applied (e.g.accept-encoding: gzip
is set for the request to the example code here), we usetransfer-encoding: chunked
in the current and previous versions.This was flagged by crates-io. I would expect most clients to handle this change without any issues but there theoretically could be some that would reject any response without
content-length
set so I'm not sure if the upgrade would be completely safe. If we assume that all clients should be able to handle this, we can close this as not a bug.The most likely change that had an impact on this behavior would be #2897. I did not look closer into the
content-length
setting code yet.This change is most likely not just about compression but possibly any layer that wraps the body.
As a follow up, I think we should consider (in a separate issue if it doesn't turn out to be the easiest solution) whether we could set
content-length
for compressed responses where the whole body is already present.The text was updated successfully, but these errors were encountered: