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
sourceimpl 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.
Trait Implementations
sourceimpl PartialEq<Response> for Response
impl PartialEq<Response> for Response
impl Eq for Response
impl StructuralEq for Response
impl StructuralPartialEq for Response
Auto Trait Implementations
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more