Repository navigation
breaking: use http types in HttpMockRequest - #273
danieleades wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
d183023 to
40359f3
Compare
40359f3 to
66741bf
Compare
49b8645 to
dc39bf8
Compare
|
I considered once myself to use the data structures of the |
this crate already exposes the Some of my changes do go a bit deeper and push more onus onto the user in the pursuit of a smaller, more focused core library. Some of the ergonomic changes are due to a change in ownership and are unavoidable (but worth it, in my opinion- and i'm not sure forcing callers to explicitly clone instead of implicitly cloning is a downgrade) while other conveniences could be reintroduced. Would you like me to try and find a halfway house? |
33408bc to
9b5111d
Compare
|
Deferring this to 0.10 so we can get 0.9 out, added it to the milestone |
9b5111d to
41dcf25
Compare
This is the request half of #259, split out as requested.
HttpMockRequestcurrently stores its URI, method, headers, scheme and version as strings, then parses or rebuilds the correspondinghttptypes whenever they are used. This stores the typed values once and validates them at the conversion boundary instead.The main benefit is maintainability: there are fewer repeated conversions, fewer panic paths, and the internal state is correct by construction. Accessors can borrow the stored values instead of allocating replacements. It also fixes IPv6 authority handling by using
http::uri::Authority, so this supersedes #208. For absolute-form targets the URI authority wins overHost; origin-form targets still useHost.The existing text wire format is preserved. Opaque header values now have a byte-safe representation, so they can still appear in remote verification diagnostics rather than causing serialization to fail. Serialization borrows the typed request where possible, avoiding per-header copies.
Excluding tests, changelog and documentation changes, this replaces roughly 255 production lines with 321: a net increase of about 66 lines. The extra code is mainly the explicit, byte-safe wire conversion and the typed public conversion error; the in-memory request model itself is simpler.
Breaking changes:
uri(),scheme(),method()andheaders()now borrow their correspondinghttptypes, andhost()returnsOption<&str>.uri_str()andheaders_vec()are removed, since they borrow strings the request no longer stores. The other existing accessors (method_str(),query_params(),query_param_length(),body_string(),body_ref(),body_vec(),body_bytes(),version_ref(), andto_http_request()as restored in Restore selected 0.8.3 APIs and add HTTP response conversion #326) are kept as thin wrappers over the typed values.http::RequestintoHttpMockRequestnow usesTryFromwith the publicHttpMockRequestConversionError. Conversions back toRequest<Bytes>,Request<String>andRequest<()>are kept.RequestMetadata::newand its publicschemefield now usehttp::uri::Schemerather than&'static str.Boxed byte bodies remain supported after rebasing onto the upstream conversion fix.
Request<()>remains supported for empty incoming requests.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