HTTPS
By default, httpmock
does not enable HTTPS support for testing. However, you can enable it on demand by using the
Cargo feature https
. When this feature is enabled, httpmock
automatically uses HTTPS for all internal communication
between the Rust API and the mock server, whether it’s a remote standalone server or a local
MockServer
instance.
It also allows your client to send HTTPS requests to the mock server.
Unified Port
httpmock
uses a unified port approach for both HTTP and HTTPS communication. This means you don’t need to change
the port or modify anything in your Rust tests to switch to HTTPS. Your client can send requests using HTTPS as needed,
and httpmock
will automatically detect HTTPS traffic on the port and transition from HTTP to HTTPS without
any additional configuration.
CA Certificate
Since HTTPS requires the use of certificates, you’ll need to accept the httpmock
CA certificate
in your client settings or, more conveniently, in your system preferences when using HTTPS.
You can find the httpmock
CA certificate in the httpmock
GitHub repository (ca.pem file).
httpmock
uses its CA certificate to generate domain-specific certificates for your tests. For instance, if you want
to mock requests from https://wikipedia.org (such as when using the httpmock
proxy feature), the mock server
will generate and cache a certificate for that domain based on the httpmock
CA certificate. Since your system
trusts the CA certificate, the self-signed, domain-specific certificate for Wikipedia will also be trusted
automatically.
Trusting the CA Certificate
Here is how you can add the httpmock
CA crtificate to your system.