Struct sharp_pencil::wrappers::Response
source · [−]pub struct Response {
pub status_code: u16,
pub headers: Headers,
pub body: Option<Box<dyn BodyWrite>>,
}
Expand description
Response type. It is just one container with a couple of parameters (headers, body, status code etc).
Fields
status_code: u16
The HTTP Status code number
headers: Headers
body: Option<Box<dyn BodyWrite>>
Implementations
sourceimpl Response
impl Response
sourcepub fn new<T: 'static + BodyWrite>(body: T) -> Response
pub fn new<T: 'static + BodyWrite>(body: T) -> Response
Create a Response
. By default, the status code is 200
and content type is “text/html; charset=UTF-8”.
Remember to set content length if necessary.
Mostly you should just get a response that is converted
from other types, which set the content length automatically.
For example:
// Content length is set automatically
let response = Response::from("Hello");
sourcepub fn status_name(&self) -> &str
pub fn status_name(&self) -> &str
Get status name.
sourcepub fn content_type(&self) -> Option<&ContentType>
pub fn content_type(&self) -> Option<&ContentType>
Returns the response content type if available.
sourcepub fn set_content_type(&mut self, mimetype: &str)
pub fn set_content_type(&mut self, mimetype: &str)
Set response content type. If the mimetype passed is a
mimetype starting with text/
or something that needs a charset,
the charset(UTF-8) parameter is appended to it.
sourcepub fn content_length(&self) -> Option<usize>
pub fn content_length(&self) -> Option<usize>
Returns the response content length if available.
sourcepub fn set_content_length(&mut self, value: usize)
pub fn set_content_length(&mut self, value: usize)
Set content length.
Sets cookie.
Trait Implementations
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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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