Repository navigation
breaking: use http types in HttpMockResponse - #274
danieleades wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
474099c to
829dedd
Compare
6f23839 to
7181cf7
Compare
7181cf7 to
7cd0fe8
Compare
8cd13db to
da12c78
Compare
|
This will shift responsibility for ownership towards the user, so users need to clone themselves before they use our methods. This is a lot of convenience to give away. |
da12c78 to
24c4d9c
Compare
Callers only need to clone if they want to retain the original response, otherwise they can move it directly. The previous borrowed conversion copied implicitly, so this makes the cost explicit and avoids it when ownership can transfer. I think that’s a reasonable trade-off |
24c4d9c to
65dc0f0
Compare
|
Deferring this to 0.10 so we can get 0.9 out, added it to the milestone |
65dc0f0 to
9b34711
Compare
This is the response half of #259, split out as requested.
HttpMockResponseis now a thin wrapper aroundhttp::Response, rather than a second, partly stringly-typed response model. Status codes, headers, body, HTTP version and extensions stay together as one valid response, and conversions useResponse::maprather than taking the response apart and rebuilding it.For users, this makes the
httpintegration more complete: response versions and middleware extensions survive round trips, and binary bodies can be echoed without allocating or accidentally changing their contents. For maintainers, it removes conversion code and makes invalid intermediate states harder to represent.Excluding tests, changelog and documentation changes, this replaces roughly 135 production lines with 77: about 58 fewer lines overall.
Breaking changes:
status(),headers()andbody()accessors returnStatusCode,&HeaderMapand&[u8].new()andno_body(), and accepts either the old argument types or typedhttpvalues. It now panics on an invalid status code, header name or header value instead of failing when the response is served.From, in both owned and borrowed forms, so existingtry_fromcalls still compile.to_http_response()from Restore selected 0.8.3 APIs and add HTTP response conversion #326 now returnshttp::Response<Bytes>directly.Owned boxed byte bodies remain supported after rebasing onto the upstream conversion fix. Callers retaining the original response can clone before converting, as with other body types.
Checks:
cargo testcargo test --all-features --libcargo clippy --all-targets --all-featurescargo fmt --all -- --checkRebase validation:
cargo +stable clippy --offline --all-targets --all-featurescargo +stable clippy --offline --all-targets --no-default-featurescargo +stable test --offline --all-features --libcargo +stable test --offline --all-features --test lib body_conversion_tests— all four boxed-body regression tests pass, adapted to this PR's API