pub struct Response {
pub status: Status,
pub headers: Headers,
pub body: Vec<u8>,
}Expand description
HTTP response.
While all members of this struct are public, there are also some dedicated
methods with identical names, providing a builder-like interface. However,
before creating a response using this struct directly, consider using the
ResponseExt trait, which provides several convenient constructors.
§Examples
use zense::http::{Header, Response, Status};
// Create response
let res = Response::new()
.status(Status::Ok)
.header(Header::ContentType, "text/plain")
.header(Header::ContentLength, 11)
.body("Hello world");Fields§
§status: StatusResponse status.
headers: HeadersResponse headers.
body: Vec<u8>Response body.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a response.
§Examples
use zense::http::Response;
// Create response
let res = Response::new();Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Converts the response into bytes.
§Examples
use zense::http::{Header, Response, Status};
// Create response
let res = Response::new()
.status(Status::Ok)
.header(Header::ContentType, "text/plain")
.header(Header::ContentLength, 11)
.body("Hello world");
// Convert response into bytes
let bytes = res.into_bytes();Source§impl Response
impl Response
Sourcepub fn status(self, status: Status) -> Self
pub fn status(self, status: Status) -> Self
Sets the status of the response.
§Examples
use zense::http::{Response, Status};
// Create response and set status
let res = Response::new()
.status(Status::Ok);Sourcepub fn header<V>(self, header: Header, value: V) -> Selfwhere
V: ToString,
pub fn header<V>(self, header: Header, value: V) -> Selfwhere
V: ToString,
Adds a header to the response.
§Examples
use zense::http::{Header, Response};
// Create response and add header
let res = Response::new()
.header(Header::ContentType, "text/plain");Sourcepub fn body<B>(self, body: B) -> Self
pub fn body<B>(self, body: B) -> Self
Sets the body of the response.
Warning: Albeit the Header::ContentLength header is required in
most cases, it’s not automatically set when using this method, since it
belongs to the low-level Response interface. Please consider using
the much more convenient ResponseExt methods.
§Examples
use zense::http::Response;
// Create response and set body
let res = Response::new()
.body("Hello world");Trait Implementations§
Source§impl IntoResponse for Response
impl IntoResponse for Response
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Converts the response into itself.