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

Set content-length for responses to HEAD requests #734

Merged
merged 4 commits into from
Jan 31, 2022

Conversation

davidpdrsn
Copy link
Member

Hyper will automatically set the length if the body as an exact size, as determined via Body::size_hint, but since axum would use an empty body for HEAD requests the content-length would be set to 0 instead of the length of the original response body.

This fixes that by having axum set the content-length before removing the body.

I also changed RouteFuture to be the future we return regardless if we hit a route or the fallback. That way we only had to make this change in one place.

Required adding some B: HttpBody bounds in a few places so we can call size_hint but hyper already requires that so its unlikely to cause breakage.

Fixes #730

@davidpdrsn davidpdrsn changed the title Set content-length internally in RouteFuture Set content-length for responses to HEAD requests Jan 31, 2022
@davidpdrsn
Copy link
Member Author

CI is unhappy since matchit 0.4.5 requires rust 2021. I'll get that resolved separately.

@davidpdrsn davidpdrsn merged commit 515495d into main Jan 31, 2022
@davidpdrsn davidpdrsn deleted the set-content-length branch January 31, 2022 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect content-length header in reply to HEAD request
2 participants