pub struct Response {
pub version: HttpVersion,
pub status: u16,
pub status_text: &'static str,
pub bytes: Vec<u8>,
pub headers: Option<Headers>,
}
Expand description
Response struct. Contains the response data and converts it to text if needed.
Fieldsยง
ยงversion: HttpVersion
HTTP protocol version.
status: u16
HTTP status code.
status_text: &'static str
According text for the status.
bytes: Vec<u8>
The request body, stored in bytes.
headers: Option<Headers>
Headers of the response
Implementationsยง
sourceยงimpl Response
impl Response
sourcepub fn new(
version: HttpVersion,
status: u16,
status_text: &'static str,
bytes: Vec<u8>,
headers: Option<Headers>
) -> Self
pub fn new( version: HttpVersion, status: u16, status_text: &'static str, bytes: Vec<u8>, headers: Option<Headers> ) -> Self
Manually create a Response instance. Use Response::ok(), Response::bad_request() etc. instead when possible.
sourcepub fn send_to<T: Write>(&mut self, stream: &mut T) -> Result<(), Error>
pub fn send_to<T: Write>(&mut self, stream: &mut T) -> Result<(), Error>
Writes the response, consuming its body.
sourcepub fn with_header(self, key: &'static str, value: String) -> Self
pub fn with_header(self, key: &'static str, value: String) -> Self
Sets a header to the response, returning the response itself. Use Response::with_content_type for the โContent-Typeโ header.
sourcepub fn with_content_type(self, value: String) -> Self
pub fn with_content_type(self, value: String) -> Self
Sets the content type of the response, returning the response itself. Note that this does not check if the content type is valid, so be careful.
sourcepub fn set_header(&mut self, key: &'static str, value: String) -> &mut Self
pub fn set_header(&mut self, key: &'static str, value: String) -> &mut Self
Sets the content length of a reference to a response
sourcepub fn set_content_length(&mut self, len: usize) -> &mut Self
pub fn set_content_length(&mut self, len: usize) -> &mut Self
Sets the content length of a reference to a response
sourcepub fn with_default_headers(self) -> Self
pub fn with_default_headers(self) -> Self
Adds optional but useful headers to a response. This includes the Content-Length header, Date header and Server header.
Trait Implementationsยง
sourceยงimpl PartialEq for Response
impl PartialEq for Response
sourceยงimpl ResponseLike for Response
impl ResponseLike for Response
sourceยงfn to_response(self) -> Response
fn to_response(self) -> Response
self
into a Response
.