Repository navigation
Releases
v0.9.0
The crate was upgraded to the Rust 2024 edition. The minimum supported Rust version
remains 1.88.
Breaking changes
server::matchersis now crate-private
(#312). Its matcher, comparator and reader
types are implementation details rather than a supported extension API; there is no
replacement public path. Custom predicates remain possible withWhen::is_true.- The body helpers
is_blank,contains_str,contains_sliceandcontains_vec
were removed (#246). Use
request.body_string().contains(".."), which also works insiderespond_with, or
request.body_ref().windows(n).any(|w| w == b"..")with a non-empty needle, and
When::body_includeswhen matching. HttpMockRequest::query_params_map()was removed
(#246). Collectquery_params()instead:
let params: HashMap<String, String> = request.query_params().into_iter().collect();
keeps the last value for duplicate keys, as the removed method did.query_params()has
returnedVec<(String, String)>since 0.8.2.- The
MockExttrait was removed andMock's publicidfield is now private
(#285). RemoveMockExtimports and
replace directmock.idfield access withmock.id().Mock::new(id, &server)is
unchanged. - The mock server only accepts cleartext HTTP/2 connections (prior knowledge, as gRPC clients
send it) when thehttp2cargo feature is enabled
(#297). Previously this worked without the
feature. It fails at runtime, not at compile time: the client sees the connection closed
after the preface and the server logs "invalid HTTP version parsed (found HTTP2 preface)".
Enablehttp2to keep serving such clients;standaloneand the Docker image already
include it. HTTPS via ALPN is unaffected, ash2was already only offered with the feature
enabled. The crate also no longer enablestokio/signalorhyper/http2for other crates
in the build, so a crate that relied on that has to enable them itself. server::state::MockServerStateandserver::state::HttpMockStateManagerare now
crate-private (#289,
#326). Neither could be used from outside
the crate beyond constructing it; code using theMockServerAPI is unaffected.- The empty
experimentalCargo feature was removed
(#316). Remove it from your dependency's
feature list; it did not enable any functionality. - The Docker image now uses a slim Debian runtime without the Rust toolchain or source tree
(#202,
1231c63).curlandwgetare no
longer installed, so healthchecks that call them need another probe: anhttpGetprobe
against/__httpmock__/ping, or from inside the container
bash -c 'exec 3<>/dev/tcp/127.0.0.1/5050'. The CA files are no longer in the image either;
usecerts/ca.pemfrom the repository orserver::DEFAULT_CA_CERTIFICATE. The executable
is now at/usr/local/bin/httpmock, with a compatibility symlink at
/usr/local/cargo/bin/httpmockso existing absolute paths continue to work. - The
tls-detectcargo feature was removed
(#333). It only enabled an internal
dependency thathttpsalready pulled in; remove it from your feature list. - Optional dependencies no longer double as cargo features:
clap,colored,headers,
hyper-rustls,if-addrs,rcgen,rustls,rustls-pki-types,serde_yaml,
tokio-rustlsandtracing-subscriberare enabled through the documented features only.
Replace any of these names in your feature list with the feature that needs them, such as
httpsorstandalone. RecordingRuleBuilder::configis now private
(#322). Its type could only be used through
type inference; configure recordings through the builder's methods.
Upgrading from 0.8
Most code needs no changes. Remove MockExt imports and use mock.id() to read a mock's
ID. Replace body().is_blank() with body_string().trim().is_empty() and
body().contains_str("x") with body_string().contains("x"). Replace query_params_map()
with query_params().into_iter().collect::<HashMap<_, _>>().
Direct imports from server::matchers must be removed; use the When API to configure
matchers instead.
Tests whose clients speak cleartext HTTP/2 to the mock server additionally need the http2
feature.
The methods deprecated since 0.8.0 (Mock::hits, hits_async, assert_hits,
assert_hits_async and When::matches) are still available and will be removed in 1.0.
Improvements
- #326: Add
HttpMockResponse::to_http_response()
for converting to an HTTP response with a byte body. The method borrows the response and
returns any conversion error. - #108: Mocks can be limited to a number of
calls withThen::up_to_n_times,Mock::up_to_n_timesorMock::up_to_n_times_async,
after which they stop matching requests. Static mock YAML files support the same limit as
up_to_n_timesunderthen.MockServer::reset(), whichstart()andconnect()call,
now also resets the call counters of static YAML mocks. (resolves
#96)
(thanks @wfchandler) - Async mock, forwarding, proxy and recording setup futures implement
Sendwhen their
inputs do, allowing registration insidetokio::spawn
(#325). When,Thenand the forwarding, proxy and recording rule builders are nowSendand
Sync(#322).- #297: httpmock's own dependency tree is about
30% smaller (74 to 52 crates without default features, 86 to 64 with them), resolving
#46 - #333:
async-traitandtls-detectare no
longer dependencies. The server now tells TLS and plain HTTP connections apart by the first
byte the client sends. - #275: Owned HTTP request and response
conversions avoid unnecessary body clones. - #299: Static mock YAML files now support
json_bodyandbody_from_file(resolves issues
#118 and
#185) - #251: The default CA certificate and key are
exposed for testing asserver::DEFAULT_CA_CERTIFICATEandserver::DEFAULT_CA_PRIVATE_KEY
(httpsfeature) (thanks @ErikMcClure) - #298: The case-sensitive body matching
introduced in v0.8.0 is now documented
Bug fixes
HttpMockServerBuilder::build()returns an error instead of panicking when the directory
of static mock files cannot be listed, and the YAML and file error messages were reworded
(904fc03)- Two error messages of the admin API changed: static mocks now report "cannot be modified or
deleted" and failed state operations "state operation failed: ...". Only clients that match
on the response body of a failed request can notice - The
http2feature now also enables HTTP/2 in the HTTPS client, soremote,httpsand
http2compile together withoutremote-https - #229: The
httpsfeature builds correctly
again (hyper-rustls/ring is enabled) (thanks @danieleades) - #242,
#326: Server TLS falls back to ring when no
rustls crypto provider is installed, instead of panicking when several providers are compiled
in (thanks @danieleades) - #243:
DELETE /recordings/:idnow deletes
recordings instead of proxy rules (thanks @danieleades) - #245: The configured
history_limitis
honored instead of a hardcoded cap (thanks @danieleades) - The
*_prefixand*_suffixmatchers no longer panic with a char-boundary error when
building a mismatch report for a request value containing multi-byte UTF-8 characters - #315: Mismatch reports print request and mock
values containing tab characters (e.g. TSV bodies) verbatim instead of re-aligning them into
columns - #318:
Recording::saveandsave_tono longer
overwrite a recording saved under the same scenario name in the same second; the second file
gets a counter suffix
(<scenario>_<timestamp>_1.yaml)
Internal improvements and CI
[lints.rust]inCargo.tomldenies warnings, replacing the old#![allow(warnings)].
Cargo caps lints for registry and git dependencies, but a path dependency on httpmock builds
with them on; use--cap-lints warnthere if a newer compiler adds a warning- #210: "style: remove unused imports" (thanks [@danieleades](https://github.com/danieleade...
v0.8.3
Minimum supported Rust version has been raised to 1.88.
The following PRs have been merged:
- #186: "Remove unused code and trait methods for cleanup" (thanks @FalkWoldmann)
- #191: "upgrade Rust" (thanks @sebdotv)
- #201: "Replace unmaintained rustls-pemfile with rustls-pki-types" (thanks @aleics)
- #205: "Fix is_false custom matcher" (thanks @dfaust)
- #206: "fix: remove unneeded 'Deserialize' trait bound" (thanks @danieleades and @FalkWoldmann)
- #211: "style: remove unneeded 'mut'" (thanks @danieleades)
All changes between since the last release:
v0.8.2...v0.8.3
v0.8.2
This release includes bug fixes, documentation enhancements and new features, such as dynamic responders.
The following pull requests have been merged:
v0.8.1
This release includes bug fixes and documentation enhancements.
The following pull requests have been merged:
- #179: "Use scheme of target url for forwarding"
v0.8.0
This release includes refactoring, dependency updates, and internal cleanups.
No breaking changes expected.
The minimum required Rust version has been increased to 1.82.
The following pull requests have been merged:
- #172: "Update Rust edition to 2021" (thanks @FalkWoldmann)
- #169: "Proxy HTTPS fix"
- #167: "Replace log and env_logger with tracing and tracing-subscriber" (thanks @FalkWoldmann)
- #166: "Remove unused code" (thanks @FalkWoldmann)
- #163: "fix: issue 162, non localhost hosts match" (thanks @Thomblin)
- #160: "Replace custom read_file with std::fs::read_to_string" (thanks @FalkWoldmann)
- #158: "Improve async executor support"
- #156: "Bump async-object-pool to replace async-std"
- #153: "ci(deps): bump actions/checkout from 4 to 5"
- #152: "Fix missing standalone routes"
- #151: "Cleanup unused test functions"
- #147: "ci(deps): bump codecov/codecov-action from 2 to 5"
- #146: "cargo(deps): update thiserror requirement from 1 to 2"
- #145: "ci(deps): bump actions/checkout from 2 to 4"
- #144: "ci(deps): bump docker/build-push-action from 4 to 6
- #141: "cargo(deps): update path-tree requirement from >=0.8.0, <0.8.1 to >=0.8.0, <0.8.4"
- #140: "ci(deps): bump docker/login-action from 1 to 3"
- #139: "ci(deps): bump withastro/action from 2 to 4"
- #138: "Create dependabot.yml" (thanks @FalkWoldmann)
- #136: "Replace async_std with tokio" (thanks @FalkWoldmann)
v0.8.0-alpha.1
BREAKING CHANGES
- A new MockServer::reset method was added that resets a mock server. Thanks for providing the pull request for this feature, @dax.
- The default port for standalone server was changed from
5000to5050due to conflicts with system services on macOS. - Custom matcher functions are now closures rather than functions.
- When::json_body_partial was renamed to
json_body_includes. - When::x_www_form_urlencoded_tuple was renamed to
form_urlencoded_tuple. - When::x_www_form_urlencoded_key_exists was renamed to
form_urlencoded_key_exists. - Error message output has been changed for better readability (e.g., when calling
Mock::assert). - Custom matcher function
When::matcheshas been renamed toWhen::is_true.
Improvements
- Record and Playback mode was added
- Many new matchers functions have been added
- Proxy Mode was added
- Website docs have been created (see https://alexliesenfeld.github.io/httpmock/)
- HTTPS support added
- Internal implementation was entirely rewritten
v0.7.0
-
BREAKING CHANGES:
- For connecting to remote
httpmockservers during tests using any of theconnectmethods like
MockServer::connect,
MockServer::connect_async,
MockServer::connect_from_env, or
MockServer::connect_from_env_async,
you must now activate theremotefeature. This feature is not enabled by default.
- For connecting to remote
-
Improvements:
- The dependency tree has been significantly slimmed down when the
remotefeature is not enabled. - If the new
remotefeature is not enabled,httpmockno longer has a dependency on a real HTTP client.
As a result, certain TLS issues previously reported by users
should no longer arise.
- The dependency tree has been significantly slimmed down when the
-
This release also updates all dependencies to the most recent version.
-
The minimum Rust version has been bumped to 1.70.
v0.7.0-rc.1
-
BREAKING CHANGES:
- For connecting to remote
httpmockservers during tests using any of theconnectmethods like
MockServer::connect,
MockServer::connect_async,
MockServer::connect_from_env, or
MockServer::connect_from_env_async,
you must now activate theremotefeature. This feature is not enabled by default.
- For connecting to remote
-
Improvements:
- The dependency tree has been significantly slimmed down when the
remotefeature is not enabled. - If the new
remotefeature is not enabled,httpmockno longer has a dependency on a real HTTP client.
As a result, certain TLS issues previously reported by users
should no longer arise.
- The dependency tree has been significantly slimmed down when the
-
This release also updates all dependencies to the most recent version.
-
The minimum Rust version has been bumped to 1.65 (and 1.70 for the remote and standalone features).
v0.6.8
- This is a maintenance release that updates all dependencies to the most recent version.
- Fixes some dependency issues with the Docker image.
v0.6.7
Version 0.6.7
- This is a maintenance release that updates all dependencies to the most recent version.