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
Represents a complete HTTP response, including status, headers, and a body. This struct is used for responses where the entire body is known upfront.
Fields§
§status: StatusCodeThe HTTP status code (e.g., 200 OK, 404 Not Found).
body: BytesThe response body, stored as a Bytes object for efficiency.
max_age: Option<u32>The max-age directive for the Cache-Control header, in seconds.
created_at: Option<u32>The UNIX timestamp when the response content was created, used for the Age header.
cache_private: Option<bool>A flag to indicate if the Cache-Control should be “private” (true) or “public” (false).
headers: Option<Vec<HttpHeader>>A list of additional HTTP headers to include in the response.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn builder(status: StatusCode) -> HttpResponseBuilder
pub fn builder(status: StatusCode) -> HttpResponseBuilder
Returns a new HttpResponseBuilder to start building a response.
Sourcepub fn no_content() -> Self
pub fn no_content() -> Self
A convenience constructor for a 204 No Content response.
Sourcepub fn bad_request(body: impl Into<Bytes>) -> Self
pub fn bad_request(body: impl Into<Bytes>) -> Self
A convenience constructor for a 400 Bad Request response.
Sourcepub fn not_found(body: impl Into<Bytes>) -> Self
pub fn not_found(body: impl Into<Bytes>) -> Self
A convenience constructor for a 404 Not Found response.
Sourcepub fn unknown_error(body: impl Into<Bytes>) -> Self
pub fn unknown_error(body: impl Into<Bytes>) -> Self
A convenience constructor for a 500 Internal Server Error response.
Sourcepub fn html(body: impl Into<Bytes>) -> Self
pub fn html(body: impl Into<Bytes>) -> Self
A convenience constructor for a 200 OK HTML response.
Sourcepub fn redirect(location: &str) -> Result<Self>
pub fn redirect(location: &str) -> Result<Self>
A convenience constructor for a 302 Temporary Redirect response.
Sourcepub fn text(body: impl Into<Bytes>) -> Self
pub fn text(body: impl Into<Bytes>) -> Self
A convenience constructor for a 200 OK plain text response.
Sourcepub fn try_from_json<T>(value: &T) -> Result<Self>
pub fn try_from_json<T>(value: &T) -> Result<Self>
Creates a 200 OK JSON response by serializing the given value.
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 JSON response with a specified status code by serializing the given value.
Sourcepub fn new_response_header(&self) -> Result<ResponseHeader>
pub fn new_response_header(&self) -> Result<ResponseHeader>
Builds a pingora::http::ResponseHeader from the HttpResponse’s properties.
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