pub struct Reply {
pub status: u16,
pub content_type: String,
pub headers: Vec<(String, String)>,
pub body: Vec<u8>,
}Expand description
A handler’s answer: any status, content type, extra headers and binary body.
Fields§
§status: u16§content_type: String§headers: Vec<(String, String)>§body: Vec<u8>Implementations§
Source§impl Reply
impl Reply
Sourcepub fn bytes(content_type: &str, body: impl Into<Vec<u8>>) -> Self
pub fn bytes(content_type: &str, body: impl Into<Vec<u8>>) -> Self
200 with a binary body (generated media: image/png, audio/mpeg, video/mp4, …).
Sourcepub fn file(content_type: &str, path: &Path) -> Self
pub fn file(content_type: &str, path: &Path) -> Self
200 with a file’s bytes; an unreadable file is a 500 naming it.
pub fn with_status(self, status: u16) -> Self
pub fn with_header(self, name: &str, value: &str) -> Self
Sourcepub fn ignore_range(self) -> Self
pub fn ignore_range(self) -> Self
Answer every request with the full body, ignoring any Range (a server
that cannot resume). Recorded as the reserved IGNORE_RANGE_HEADER,
which the mock consumes and never sends.
Sourcepub fn drop_connection() -> Self
pub fn drop_connection() -> Self
Close the connection without writing any response: a half-accepted request (the
client sent it, the server never answered). The request is still recorded and logged
(status 0 in RequestLog). Recorded as the reserved DROP_HEADER, which the
mock consumes and never sends.
Sourcepub fn is_drop(&self) -> bool
pub fn is_drop(&self) -> bool
True for a Reply::drop_connection reply.
Sourcepub fn cut_after(self, bytes: u64) -> Self
pub fn cut_after(self, bytes: u64) -> Self
Send the response head (with the full Content-Length), then only the first
bytes body bytes, then close the connection: a download dropped mid-transfer.
Applies after any Range slicing. Recorded as the reserved CUT_AFTER_HEADER,
which the mock consumes and never sends.