pub struct MockResponse {
pub status: u16,
pub headers: HashMap<String, String>,
pub body: Vec<u8>,
pub content_type: String,
pub delay_ms: u64,
}Expand description
A mocked HTTP response
Fields§
§status: u16HTTP status code
headers: HashMap<String, String>Response headers
body: Vec<u8>Response body
content_type: StringContent type
delay_ms: u64Artificial delay in milliseconds
Implementations§
Source§impl MockResponse
impl MockResponse
Sourcepub fn json<T: Serialize>(data: &T) -> ProbarResult<Self>
pub fn json<T: Serialize>(data: &T) -> ProbarResult<Self>
Create a JSON response
Sourcepub const fn with_status(self, status: u16) -> Self
pub const fn with_status(self, status: u16) -> Self
Set status code
Sourcepub fn with_json<T: Serialize>(self, data: &T) -> ProbarResult<Self>
pub fn with_json<T: Serialize>(self, data: &T) -> ProbarResult<Self>
Set JSON body
Sourcepub fn with_header(self, key: &str, value: &str) -> Self
pub fn with_header(self, key: &str, value: &str) -> Self
Add a header
Sourcepub fn with_content_type(self, content_type: &str) -> Self
pub fn with_content_type(self, content_type: &str) -> Self
Set content type
Sourcepub const fn with_delay(self, delay_ms: u64) -> Self
pub const fn with_delay(self, delay_ms: u64) -> Self
Set delay
Sourcepub fn body_string(&self) -> String
pub fn body_string(&self) -> String
Get body as string
Trait Implementations§
Source§impl Clone for MockResponse
impl Clone for MockResponse
Source§fn clone(&self) -> MockResponse
fn clone(&self) -> MockResponse
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MockResponse
impl Debug for MockResponse
Source§impl Default for MockResponse
impl Default for MockResponse
Source§impl<'de> Deserialize<'de> for MockResponse
impl<'de> Deserialize<'de> for MockResponse
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for MockResponse
impl RefUnwindSafe for MockResponse
impl Send for MockResponse
impl Sync for MockResponse
impl Unpin for MockResponse
impl UnsafeUnpin for MockResponse
impl UnwindSafe for MockResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().