pub struct ClientBuilder { /* private fields */ }Expand description
Builder for constructing a MockServerClient.
§Example
use mockserver_client::ClientBuilder;
let client = ClientBuilder::new("localhost", 1080)
.context_path("/api")
.secure(true)
.build()
.unwrap();Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new(host: impl Into<String>, port: u16) -> Self
pub fn new(host: impl Into<String>, port: u16) -> Self
Create a new builder targeting the given host and port.
Sourcepub fn context_path(self, path: impl Into<String>) -> Self
pub fn context_path(self, path: impl Into<String>) -> Self
Set a context path prefix (e.g., “/mockserver” if deployed behind a reverse proxy).
Sourcepub fn tls_verify(self, verify: bool) -> Self
pub fn tls_verify(self, verify: bool) -> Self
Whether to verify TLS certificates (default: true).
Sourcepub fn control_plane_bearer_token(self, token: impl Into<String>) -> Self
pub fn control_plane_bearer_token(self, token: impl Into<String>) -> Self
Attach an Authorization: Bearer <token> header to every control-plane
request the built client sends.
Use this when the server requires a JWT on the control plane
(mockserver.controlPlaneJWTAuthenticationRequired=true). The client does
not generate the token — supply the JWT string here. The header is only
sent on control-plane (/mockserver/*) requests issued by this client; it
is not added to any proxied/data-plane traffic.
§Example
use mockserver_client::ClientBuilder;
let client = ClientBuilder::new("localhost", 1080)
.secure(true)
.control_plane_bearer_token("eyJhbGciOi...")
.build()
.unwrap();Sourcepub fn ca_cert_pem_path(self, path: impl AsRef<Path>) -> Self
pub fn ca_cert_pem_path(self, path: impl AsRef<Path>) -> Self
Trust the given CA certificate (PEM file path) when connecting over HTTPS.
Reads the PEM file and adds it as an additional trusted root so a
MockServer HTTPS certificate issued by that CA validates. Compose with
secure(true). The CA is added to — not a replacement for
— the platform’s default trust store.
Errors from reading the file surface when build is called.
Sourcepub fn ca_cert_pem(self, bytes: impl Into<Vec<u8>>) -> Self
pub fn ca_cert_pem(self, bytes: impl Into<Vec<u8>>) -> Self
Trust the given CA certificate (PEM bytes) when connecting over HTTPS.
In-memory counterpart to ca_cert_pem_path.
Sourcepub fn client_cert_pem(
self,
cert_path: impl AsRef<Path>,
key_path: impl AsRef<Path>,
) -> Self
pub fn client_cert_pem( self, cert_path: impl AsRef<Path>, key_path: impl AsRef<Path>, ) -> Self
Present a client certificate + private key (PEM) for mutual TLS (mTLS).
Reads the certificate and PKCS#8 private key PEM files and configures them
as the client identity used in the TLS handshake — required when the
server enforces mockserver.controlPlaneTLSMutualAuthenticationRequired.
Errors from reading either file, or from building the identity, surface
when build is called.
Sourcepub fn build(self) -> Result<MockServerClient>
pub fn build(self) -> Result<MockServerClient>
Build the client.