pub struct Response { /* private fields */ }
Expand description
Wrapper over an HTTP Response.
The Response is created using a Version
and a StatusCode
. When creating a Response object,
the body is initialized to None
and the header is initialized with the default
value. The body
can be updated with a call to set_body
. The header can be updated with set_content_type
and
set_server
.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(http_version: Version, status_code: StatusCode) -> Self
pub fn new(http_version: Version, status_code: StatusCode) -> Self
Creates a new HTTP Response
with an empty body.
Sourcepub fn set_body(&mut self, body: Body)
pub fn set_body(&mut self, body: Body)
Updates the body of the Response
.
This function has side effects because it also updates the headers:
ContentLength
: this is set to the length of the specified body.
Sourcepub fn set_content_type(&mut self, content_type: MediaType)
pub fn set_content_type(&mut self, content_type: MediaType)
Updates the content type of the Response
.
Sourcepub fn set_deprecation(&mut self)
pub fn set_deprecation(&mut self)
Marks the Response
as deprecated.
Sourcepub fn set_encoding(&mut self)
pub fn set_encoding(&mut self)
Updates the encoding type of Response
.
Sourcepub fn set_server(&mut self, server: &str)
pub fn set_server(&mut self, server: &str)
Sets the HTTP response server.
Sourcepub fn allow_method(&mut self, method: Method)
pub fn allow_method(&mut self, method: Method)
Allows a specific HTTP method.
Sourcepub fn write_all<T: Write>(&self, buf: &mut T) -> Result<(), WriteError>
pub fn write_all<T: Write>(&self, buf: &mut T) -> Result<(), WriteError>
Writes the content of the Response
to the specified buf
.
§Errors
Returns an error when the buffer is not large enough.
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the Status Code of the Response.
Sourcepub fn body(&self) -> Option<Body>
pub fn body(&self) -> Option<Body>
Returns the Body of the response. If the response does not have a body, it returns None.
Sourcepub fn content_length(&self) -> i32
pub fn content_length(&self) -> i32
Returns the Content Length of the response.
Sourcepub fn content_type(&self) -> MediaType
pub fn content_type(&self) -> MediaType
Returns the Content Type of the response.
Sourcepub fn deprecation(&self) -> bool
pub fn deprecation(&self) -> bool
Returns the deprecation status of the response.
Sourcepub fn http_version(&self) -> Version
pub fn http_version(&self) -> Version
Returns the HTTP Version of the response.