pub struct HttpResponse {
pub status: StatusCode,
pub body: ResponseBody,
pub content_type: &'static str,
pub headers: Vec<(String, String)>,
pub cookies: Vec<Cookie>,
}Expand description
Re-exported public API.
Public Caelix type HttpResponse.
Fields§
§status: StatusCodeThe status value.
body: ResponseBodyThe body value.
content_type: &'static strThe content_type value.
headers: Vec<(String, String)>Extra response headers applied by the HTTP adapter.
Owned name/value pairs so callers can set dynamic values
(e.g. Content-Disposition with a generated filename). This is a
simple list, not a full HeaderMap with multi-value / typed APIs.
Cookies appended as separate Set-Cookie response headers.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(
status: StatusCode,
body: Vec<u8>,
content_type: &'static str,
) -> Self
pub fn new( status: StatusCode, body: Vec<u8>, content_type: &'static str, ) -> Self
Runs the new public API operation.
Sourcepub fn json(status: StatusCode, body: impl Serialize) -> Self
pub fn json(status: StatusCode, body: impl Serialize) -> Self
Serializes body as JSON. This is the single place JSON encoding
happens — everything else below routes through here.
Sourcepub fn text(status: StatusCode, body: impl Into<String>) -> Self
pub fn text(status: StatusCode, body: impl Into<String>) -> Self
Runs the text public API operation.
Sourcepub fn bytes(status: StatusCode, body: impl Into<Vec<u8>>) -> Self
pub fn bytes(status: StatusCode, body: impl Into<Vec<u8>>) -> Self
Runs the bytes public API operation.
Sourcepub fn body_bytes(&self) -> Option<&[u8]>
pub fn body_bytes(&self) -> Option<&[u8]>
Buffered body bytes, if this response is not streaming.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Append a response header. Values may be dynamic (String or &str).
Prefer this when building a response by chaining.
Sourcepub fn insert_header(
&mut self,
name: impl Into<String>,
value: impl Into<String>,
)
pub fn insert_header( &mut self, name: impl Into<String>, value: impl Into<String>, )
Append a response header in place (e.g. from an interceptor).
Appends a response cookie.
Appends a response cookie in place.