Struct perseus::turbine::ApiResponse
source · pub struct ApiResponse {
pub body: String,
pub headers: HeaderMap,
pub status: StatusCode,
}
Expand description
The integration-agnostic representation of the response Perseus will give to HTTP requests.
Fields§
§body: String
The actual response body.
headers: HeaderMap
The additional headers for the response. These will not include things like caching directives and the like, as they are expected to be handled by integrations.
status: StatusCode
The HTTP status code of the response.
Implementations§
source§impl ApiResponse
impl ApiResponse
sourcepub fn err(status: StatusCode, body: &str) -> Self
pub fn err(status: StatusCode, body: &str) -> Self
Creates some other error response.
sourcepub fn add_header(&mut self, k: HeaderName, v: HeaderValue)
pub fn add_header(&mut self, k: HeaderName, v: HeaderValue)
Adds the given header to this response.
sourcepub fn content_type(self, mime_type: &str) -> Self
pub fn content_type(self, mime_type: &str) -> Self
Sets the Content-Type
HTTP header to the given MIME type, which tells
the browser what file type it has actually been given. For HTML, this is
especially important!
As this is typically called last, and only once, it consumes self
for
ergonomics. If this is not desired, the .add_header()
method can
be manually invoked.
Panics
This will panic if the given MIME type contains invalid ASCII characters.