pub struct HttpResponse {
pub status: StatusCode,
pub body: Bytes,
pub max_age: Option<u32>,
pub created_at: Option<u32>,
pub cache_private: Option<bool>,
pub headers: Option<Vec<HttpHeader>>,
}Expand description
Main HTTP response struct for handling complete responses
Fields§
§status: StatusCodeHTTP status code (200 OK, 404 Not Found, etc)
body: BytesResponse body as bytes
max_age: Option<u32>Cache control max-age value in seconds
created_at: Option<u32>Timestamp when response was created
cache_private: Option<bool>Whether cache should be private (true) or public (false)
headers: Option<Vec<HttpHeader>>Additional HTTP headers
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn no_content() -> Self
pub fn no_content() -> Self
Creates a new HTTP response with 204 No Content status and no-store cache control
Sourcepub fn bad_request(body: Bytes) -> Self
pub fn bad_request(body: Bytes) -> Self
Creates a new HTTP response with 400 Bad Request status and the given body
Sourcepub fn not_found(body: Bytes) -> Self
pub fn not_found(body: Bytes) -> Self
Creates a new HTTP response with 404 Not Found status and the given body
Sourcepub fn unknown_error(body: Bytes) -> Self
pub fn unknown_error(body: Bytes) -> Self
Creates a new HTTP response with 500 Internal Server Error status and the given body
Sourcepub fn html(body: Bytes) -> Self
pub fn html(body: Bytes) -> Self
Creates a new HTTP response with 200 OK status, HTML content type, and the given body
Sourcepub fn redirect(location: &str) -> Result<Self>
pub fn redirect(location: &str) -> Result<Self>
Creates a new HTTP response with 302 Temporary Redirect status to the given location
Sourcepub fn text(body: Bytes) -> Self
pub fn text(body: Bytes) -> Self
Creates a new HTTP response with 200 OK status, text/plain content type, and the given body
Sourcepub fn try_from_json_status<T>(value: &T, status: StatusCode) -> Result<Self>
pub fn try_from_json_status<T>(value: &T, status: StatusCode) -> Result<Self>
Creates a new HTTP response from a serializable value with the specified status code
Sourcepub fn try_from_json<T>(value: &T) -> Result<Self>
pub fn try_from_json<T>(value: &T) -> Result<Self>
Creates a new HTTP response from a serializable value with 200 OK status
Sourcepub fn new_response_header(&self) -> Result<ResponseHeader>
pub fn new_response_header(&self) -> Result<ResponseHeader>
Builds and returns the HTTP response headers based on the response configuration
Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more