Skip to content

breaking: use http types in HttpMockResponse - #274

Open
danieleades wants to merge 2 commits into
httpmock:masterfrom
danieleades:agent/use-http-response-types
Open

danieleades wants to merge 2 commits into
httpmock:masterfrom
danieleades:agent/use-http-response-types

Conversation

@danieleades

@danieleades danieleades commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

This is the response half of #259, split out as requested.

HttpMockResponse is now a thin wrapper around http::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 use Response::map rather than taking the response apart and rebuilding it.

For users, this makes the http integration 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:

  • The response fields are private and the type no longer implements Serde. The status(), headers() and body() accessors return StatusCode, &HeaderMap and &[u8].
  • The builder keeps its existing methods, including new() and no_body(), and accepts either the old argument types or typed http values. It now panics on an invalid status code, header name or header value instead of failing when the response is served.
  • Response conversions use infallible From, in both owned and borrowed forms, so existing try_from calls still compile. to_http_response() from Restore selected 0.8.3 APIs and add HTTP response conversion #326 now returns http::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 test
  • cargo test --all-features --lib
  • cargo clippy --all-targets --all-features
  • cargo fmt --all -- --check

Rebase validation:

  • cargo +stable clippy --offline --all-targets --all-features
  • cargo +stable clippy --offline --all-targets --no-default-features
  • cargo +stable test --offline --all-features --lib
  • cargo +stable test --offline --all-features --test lib body_conversion_tests — all four boxed-body regression tests pass, adapted to this PR's API

@codecov

codecov Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@danieleades
danieleades force-pushed the agent/use-http-response-types branch 2 times, most recently from 474099c to 829dedd Compare August 9, 2026 19:58
@danieleades
danieleades marked this pull request as ready for review August 9, 2026 20:05
@danieleades
danieleades force-pushed the agent/use-http-response-types branch 6 times, most recently from 6f23839 to 7181cf7 Compare August 16, 2026 12:39
@danieleades
danieleades force-pushed the agent/use-http-response-types branch from 7181cf7 to 7cd0fe8 Compare August 17, 2026 18:50
@danieleades
danieleades force-pushed the agent/use-http-response-types branch 2 times, most recently from 8cd13db to da12c78 Compare September 20, 2026 15:36
@alexliesenfeld

Copy link
Copy Markdown
Member

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.

@danieleades
danieleades force-pushed the agent/use-http-response-types branch from da12c78 to 24c4d9c Compare September 23, 2026 12:08
@danieleades

Copy link
Copy Markdown
Contributor Author

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.

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

@danieleades
danieleades force-pushed the agent/use-http-response-types branch from 24c4d9c to 65dc0f0 Compare September 30, 2026 07:37
@FalkWoldmann FalkWoldmann added this to the 0.10 milestone Oct 20, 2026
@FalkWoldmann

Copy link
Copy Markdown
Member

Deferring this to 0.10 so we can get 0.9 out, added it to the milestone

@danieleades
danieleades force-pushed the agent/use-http-response-types branch from 65dc0f0 to 9b34711 Compare October 22, 2026 17:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants