Should `Request<B>` and `Response<B>` implement `Body`?
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- rust
- Domain
- networking
Research direction
Start by reviewing the Body implementations for Request<B> and Response<B>, then inspect the linked axum src/body.rs and src/response/mod.rs references. Determine whether removing those implementations avoids the demonstrated metadata loss and assess the breaking-change impact before deciding what tests or API updates are needed.
Written by the indexing model from the issue text.
Description
Today I discovered an unfortunate interaction between axum and http-body.
In axum you're able to write this:
use axum::{
body::{box_body, Body, BoxBody},
handler::get,
http::Response,
Router,
};
let app = Router::new().route(
"/",
get(|| async {
// Build a response with a header.
let response: Response<Body> = Response::builder()
.header("x-foo", "foo")
.body(Body::empty())
.unwrap();
// Since `Response<B>` implements `Body`, we can use `box_body` to
// convert it into a `BoxBody`.
let body: BoxBody = box_body(response);
// And because `BoxBody` implements `IntoResponse` we can return it
// from handlers.
//
// However `impl IntoResponse for BoxBody` simply does
// `Response::new(self)` thus removing headers, status, etc.
body
}),
);
So because Response<B> implements Body it can be used with box_body but that ends up removing everything from the response except the body. I think being able to return bodies directly from axum handlers is a nice feature its just unfortunate that this particular thing compiles.
BoxBody's IntoResponse impl is here.
One could say "well just don't do this" but would be nice if it didn't compile at all, which could be done by removing impl Body for {Response, Request}<B>. Thats of course a breaking change 😞
- Dominant language
- Rust
- Stars
- 173
- Forks
- 71
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from hyperium/http-body
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Feature Proposal: Add `try_clone` method to `Body` traitPossibly taken @pearzl claimed this 380 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
All issues in hyperium/http-body
Similar issues
-
An EXE started from the shell with MAXALLOC FFFFh leaves a 0-paragraph free block after its ownOpenbug low-priority
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
dividebysandwich/rust-dos#629 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
eliasstravik/herdr-projects#758 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
enhancement needs:sonnet ready-for-agent
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
kinqsradio/orbyn-engineering#297 ·
Maintainers usually reply within 1 day