pub struct ResponseHandler { /* private fields */ }Implementations§
Source§impl ResponseHandler
impl ResponseHandler
Sourcepub fn into_response(
self,
request_headers: &HeaderMap,
) -> Result<Response<BoxBody>, Error>
pub fn into_response( self, request_headers: &HeaderMap, ) -> Result<Response<BoxBody>, Error>
build response
Sourcepub fn with_status(self, status: &StatusCode) -> Self
pub fn with_status(self, status: &StatusCode) -> Self
set http status code
Sourcepub fn with_header(
self,
key: impl Into<String>,
value: Option<impl Into<String>>,
) -> Self
pub fn with_header( self, key: impl Into<String>, value: Option<impl Into<String>>, ) -> Self
add custom header
Sourcepub fn with_headers<K, V, I>(self, headers: I) -> Self
pub fn with_headers<K, V, I>(self, headers: I) -> Self
add custom headers
Sourcepub fn with_custom_headers(
self,
custom_headers: Option<&HashMap<String, Option<String>>>,
) -> Self
pub fn with_custom_headers( self, custom_headers: Option<&HashMap<String, Option<String>>>, ) -> Self
Apply an operator’s custom respond.headers, always last —
after whichever with_text/with_json_body/with_binary_body
call already set a default content-type (RFC 065’s override
rule: an explicit content-type always wins over the derived
default, on every body source, uniformly).
§Why one method instead of each call site’s own if let
Before this, every response-building function repeated
if let Some(custom_headers) = custom_headers { response_handler = response_handler.with_headers(custom_headers.to_owned()); }
itself, and the two places that got the ordering wrong
(json_response, and FileResponse’s own binary-file path) each
silently let the derived content-type win instead — because
self.headers is a plain HashMap, whichever call happens last
wins for that key, and there was nothing forcing “last” to always
mean “the custom headers.” Routing every call site through this
one method, called only after the body is set, makes that
ordering the only way to call it — not a convention that can
drift a third time.
Sourcepub fn with_text(
self,
text: impl Into<String>,
content_type: Option<&str>,
) -> Self
pub fn with_text( self, text: impl Into<String>, content_type: Option<&str>, ) -> Self
add text to body
Sourcepub fn with_json_body(self, body: impl Into<String>) -> Self
pub fn with_json_body(self, body: impl Into<String>) -> Self
treat response as json