Struct kvarn::FatResponse
source · pub struct FatResponse { /* private fields */ }
Expand description
A Response
returned by handle_request()
.
Contains all preference information to the lower-level
functions. Most things like content-length
, content-encoding
,
content-type
, cache-control
, and server caching will be
automatically handled.
Implementations§
source§impl FatResponse
impl FatResponse
sourcepub fn new(
response: Response<Bytes>,
server_cache_preference: ServerCachePreference
) -> Self
pub fn new( response: Response<Bytes>, server_cache_preference: ServerCachePreference ) -> Self
Create a new FatResponse
with server_cache_preference
advising Kvarn of how to cache the content.
All other preferences are set to Full
with a future
of None
.
Choose
comprash::ServerCachePreference::Full
if the page is one regularly accessed,comprash::ServerCachePreference::None
if the page is rarely accessed or if the runtime cost of getting the page is minimal.comprash::ServerCachePreference::QueryMatters
should be avoided. It should be used when you have a page dictated by the query. Consider using aPrime
extension to make all requests act as only one of a few queries to increase performance by reducing cache size.
sourcepub fn cache(response: Response<Bytes>) -> Self
pub fn cache(response: Response<Bytes>) -> Self
Create a new FatResponse
with all preferences set to Full
and no Future
.
Use the with_*
methods to change the defaults.
sourcepub fn no_cache(response: Response<Bytes>) -> Self
pub fn no_cache(response: Response<Bytes>) -> Self
Create a new FatResponse
with all cache preferences set to None
,
compress preference set to Full
, and no Future
.
Use the with_*
methods to change the defaults.
sourcepub fn with_client_cache(self, preference: ClientCachePreference) -> Self
pub fn with_client_cache(self, preference: ClientCachePreference) -> Self
Set the inner comprash::ClientCachePreference
.
sourcepub fn with_server_cache(self, preference: ServerCachePreference) -> Self
pub fn with_server_cache(self, preference: ServerCachePreference) -> Self
Set the inner comprash::ServerCachePreference
.
sourcepub fn with_compress(self, preference: CompressPreference) -> Self
pub fn with_compress(self, preference: CompressPreference) -> Self
Set the inner comprash::CompressPreference
.
sourcepub fn with_future(self, future: ResponsePipeFuture) -> Self
pub fn with_future(self, future: ResponsePipeFuture) -> Self
Set the inner future
.
sourcepub fn with_future_and_len(
self,
future: ResponsePipeFuture,
new_len: usize
) -> Self
pub fn with_future_and_len( self, future: ResponsePipeFuture, new_len: usize ) -> Self
Set the inner future
and
overrides the length of the body. Only has an effect on HTTP/1.1 connections. Should be used
with caution.
This is used in the streaming body extension.
sourcepub fn with_future_and_maybe_len(
self,
future: (ResponsePipeFuture, Option<usize>)
) -> Self
pub fn with_future_and_maybe_len( self, future: (ResponsePipeFuture, Option<usize>) ) -> Self
sourcepub fn with_content_type(self, content_type: &Mime) -> Self
pub fn with_content_type(self, content_type: &Mime) -> Self
Set the content-type
header of the inner response to content_type
.
Panics
Panics if the display implementation of content_type
produces illegal bytes for
HeaderValue
.
It’s unknown if this can even happen at all.
If it does happen, it’s in the Mime::params
.
sourcepub fn into_parts(
self
) -> (Response<Bytes>, ClientCachePreference, ServerCachePreference, CompressPreference, Option<(ResponsePipeFuture, Option<usize>)>)
pub fn into_parts( self ) -> (Response<Bytes>, ClientCachePreference, ServerCachePreference, CompressPreference, Option<(ResponsePipeFuture, Option<usize>)>)
Turn self
into a tuple of all it’s parts.