pub struct MockServer {
pub base: String,
/* private fields */
}Fields§
§base: StringImplementations§
Source§impl MockServer
impl MockServer
Sourcepub fn start(routes: Vec<Route>) -> Result<Self>
pub fn start(routes: Vec<Route>) -> Result<Self>
Static JSON routes; unmatched requests get 404 {"error":"unmocked"}.
Sourcepub fn start_static(
routes: Vec<(Option<String>, String, Reply)>,
) -> Result<Self>
pub fn start_static( routes: Vec<(Option<String>, String, Reply)>, ) -> Result<Self>
Static routes answered with full Replys (binary bodies, extra headers such as a
strong ETag, Reply::ignore_range, Reply::cut_after): (method, path, reply),
first match wins, None method matches any, query ignored; unmatched requests get 404.
Sourcepub fn start_with<R: Into<Reply>>(
handler: impl Fn(&Request, &str) -> R + Send + Sync + 'static,
) -> Result<Self>
pub fn start_with<R: Into<Reply>>( handler: impl Fn(&Request, &str) -> R + Send + Sync + 'static, ) -> Result<Self>
Dynamic handler: handler(request, base_url) answers every request. base_url
(http://127.0.0.1:<port>) lets a reply point the client back at the mock (a job’s
result URL). Return a Reply, or an Option<Reply> where None means 404. A
panicking handler yields a 500 instead of killing the server.
Sourcepub fn start_opts<R: Into<Reply>>(
opts: MockOptions,
handler: impl Fn(&Request, &str) -> R + Send + Sync + 'static,
) -> Result<Self>
pub fn start_opts<R: Into<Reply>>( opts: MockOptions, handler: impl Fn(&Request, &str) -> R + Send + Sync + 'static, ) -> Result<Self>
MockServer::start_with plus MockOptions: a chosen port, request limits
(431/413/501), a connection cap (503), linger/drain, and a per-request log hook.
Rejections are written by the mock; the handler never sees those requests.
Sourcepub fn shutdown_handle(&self) -> ShutdownHandle
pub fn shutdown_handle(&self) -> ShutdownHandle
A handle that stops this server from any thread.