Skip to content

breaking: use standard body conversions - #275

Merged
FalkWoldmann merged 1 commit into
httpmock:masterfrom
danieleades:agent/simplify-body-conversions
Sep 20, 2026
Merged

FalkWoldmann merged 1 commit into
httpmock:masterfrom
danieleades:agent/simplify-body-conversions

Conversation

@danieleades

@danieleades danieleades commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

This is the body-conversion cleanup from #259, split out so it can be reviewed independently.

The private IntoMockBytes trait models every body conversion as fallible, even though all of its implementations are infallible. This replaces it with the standard Into<HttpMockBytes> conversion and removes the dead error path.

Owned http::Request and http::Response conversions now move their bodies instead of borrowing and cloning them. That removes an unnecessary Clone bound, supports non-Clone body types, and avoids copying Vec<u8> and String bodies. Borrowed conversions remain available when the caller wants to retain the source.

Excluding tests, changelog and documentation changes, this replaces roughly 80 production lines with 52: about 28 fewer lines overall.

One deliberate narrowing is that Box<[u8]> bodies no longer convert directly. That support is niche, adds an orphan-rule API commitment, and is not used internally. Existing callers can map the body through Bytes::from or Vec::from; both take ownership of the same allocation, so this does not add a copy. Empty () bodies remain supported because Request<()> and Response<()> are conventional HTTP message types.

Checks:

  • cargo test
  • cargo test --all-features --lib
  • cargo clippy --all-targets --all-features
  • cargo fmt --all -- --check

@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/common/data.rs 90.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@danieleades
danieleades marked this pull request as ready for review August 9, 2026 20:05
@danieleades
danieleades force-pushed the agent/simplify-body-conversions branch 5 times, most recently from d193b7d to 60d0539 Compare August 16, 2026 12:40
@danieleades
danieleades force-pushed the agent/simplify-body-conversions branch from 60d0539 to 9741223 Compare August 17, 2026 18:50
@danieleades
danieleades force-pushed the agent/simplify-body-conversions branch from 755811b to 0e2e381 Compare September 20, 2026 14:09
@FalkWoldmann

FalkWoldmann commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Nit: Can you deduplictae the code in the from impls?

@FalkWoldmann
FalkWoldmann merged commit 09f3cce into httpmock:master Sep 20, 2026
13 checks passed
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.

2 participants