pub struct HttpResponse {Show 13 fields
pub status_code: Option<u16>,
pub headers: Option<HashMap<String, Vec<String>>>,
pub body: Option<String>,
pub delay: Option<Delay>,
pub cookies: Option<HashMap<String, String>>,
pub reason_phrase: Option<String>,
pub status_code_range: Option<String>,
pub trailers: Option<HashMap<String, Vec<String>>>,
pub generate_from_schema: Option<String>,
pub connection_options: Option<ConnectionOptions>,
pub recover_after: Option<RecoverAfter>,
pub primary: Option<bool>,
pub extra: Extra,
}Expand description
Builder for an HTTP response action.
§Example
use mockserver_client::HttpResponse;
let response = HttpResponse::new()
.status_code(201)
.header("Location", "/api/users/42")
.body("{\"id\": 42}");Fields§
§status_code: Option<u16>§headers: Option<HashMap<String, Vec<String>>>§body: Option<String>§delay: Option<Delay>Response cookies (single value per name; emitted as Set-Cookie).
reason_phrase: Option<String>HTTP reason phrase (e.g. "Not Found"); overrides the default for the
status code.
status_code_range: Option<String>A status-code range to respond with a random status from (e.g. "2xx").
trailers: Option<HashMap<String, Vec<String>>>Response trailers (HTTP/2 trailing headers), multiple values per key.
generate_from_schema: Option<String>Generate the response body from an inline/JSON-schema string.
connection_options: Option<ConnectionOptions>Connection-level options (chunking, content-length, socket close, …).
recover_after: Option<RecoverAfter>Fail the first N requests then recover (circuit-breaker style).
primary: Option<bool>Mark this response as the primary action of a composite expectation.
extra: ExtraForward-compatibility catch-all for response fields the typed model does not yet name.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn status_code(self, code: u16) -> Self
pub fn status_code(self, code: u16) -> Self
Set the HTTP status code.
Sourcepub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a response header.
Add a response cookie (single value per name).
Sourcepub fn reason_phrase(self, reason_phrase: impl Into<String>) -> Self
pub fn reason_phrase(self, reason_phrase: impl Into<String>) -> Self
Set the HTTP reason phrase (e.g. "Not Found").
Sourcepub fn status_code_range(self, range: impl Into<String>) -> Self
pub fn status_code_range(self, range: impl Into<String>) -> Self
Set a status-code range to respond with a random status from (e.g. "2xx").
Sourcepub fn trailer(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn trailer(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a response trailer (HTTP/2 trailing header), multiple values per key.
Sourcepub fn generate_from_schema(self, schema: impl Into<String>) -> Self
pub fn generate_from_schema(self, schema: impl Into<String>) -> Self
Generate the response body from a schema string.
Sourcepub fn connection_options(self, options: ConnectionOptions) -> Self
pub fn connection_options(self, options: ConnectionOptions) -> Self
Set connection-level options.
Sourcepub fn recover_after(self, recover_after: RecoverAfter) -> Self
pub fn recover_after(self, recover_after: RecoverAfter) -> Self
Set a recover-after (fail-first-N) policy.
Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HttpResponse
impl Debug for HttpResponse
Source§impl Default for HttpResponse
impl Default for HttpResponse
Source§fn default() -> HttpResponse
fn default() -> HttpResponse
Source§impl<'de> Deserialize<'de> for HttpResponse
impl<'de> Deserialize<'de> for HttpResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for HttpResponse
impl PartialEq for HttpResponse
Source§fn eq(&self, other: &HttpResponse) -> bool
fn eq(&self, other: &HttpResponse) -> bool
self and other values to be equal, and is used by ==.