pub struct CachedResponse {
pub parts: Parts,
pub body: CachedBody,
pub duration: Option<Duration>,
}
Expand description
Cached HTTP response.
Caching the body is handled by CachedBody.
Fields§
§parts: Parts
Response parts.
body: CachedBody
Response body.
duration: Option<Duration>
Optional duration.
Implementations§
Source§impl CachedResponse
impl CachedResponse
Sourcepub async fn new_for<BodyT>(
uri: &Uri,
response: Response<BodyT>,
declared_body_size: Option<usize>,
preferred_encoding: Encoding,
skip_encoding: bool,
caching_configuration: &CachingConfiguration,
encoding_configuration: &EncodingConfiguration,
) -> Result<Self, ErrorWithResponsePieces<ReadBodyError, BodyT>>
pub async fn new_for<BodyT>( uri: &Uri, response: Response<BodyT>, declared_body_size: Option<usize>, preferred_encoding: Encoding, skip_encoding: bool, caching_configuration: &CachingConfiguration, encoding_configuration: &EncodingConfiguration, ) -> Result<Self, ErrorWithResponsePieces<ReadBodyError, BodyT>>
Constructor.
Reads the response body and stores it as Bytes.
If known_body_size
is not None then that’s the size we expect. Otherwise
we’ll try to read to max_body_size
and will expect at least min_body_size
.
In either case we will return an error if the body wasn’t completely read (we won’t cache incomplete bodies!), together with ResponsePieces, which can be used by the caller to reconstruct the original response.
preferred_encoding
is the encoding in which we want to store the body. If the response’s
encoding is different from what we want then it will be reencoded, unless the XX-Encode
header is “false”, in which case it’s as if preferred_encoding
were
Identity.
If an Identity is created during this reencoding then it will also be
stored if keep_identity_encoding
is true.
If the response doesn’t already have a Last-Modified
header, we will set it to the
current time.
Sourcepub fn clone_with_body(&self, body: CachedBody) -> Self
pub fn clone_with_body(&self, body: CachedBody) -> Self
Clone with new body.
Sourcepub async fn to_response<BodyT>(
&self,
encoding: &Encoding,
configuration: &EncodingConfiguration,
) -> Result<(Response<BodyT>, Option<Self>)>
pub async fn to_response<BodyT>( &self, encoding: &Encoding, configuration: &EncodingConfiguration, ) -> Result<(Response<BodyT>, Option<Self>)>
Create a Response.
If we don’t have the specified encoding then we will reencode from another encoding, storing the result so that we won’t have to encode it again.
If an Identity is created during this reencoding then it will also be
stored if keep_identity_encoding
is true.
If the stored XX-Encode
header is “false” then will ignore the specified encoding and
return an Identity response.
Returns a modified clone if reencoding caused a new encoding to be stored. Note that cloning should be cheap due to our use of Bytes in the body.
Trait Implementations§
Source§impl CacheWeight for CachedResponse
impl CacheWeight for CachedResponse
Source§fn cache_weight(&self) -> usize
fn cache_weight(&self) -> usize
Source§impl Clone for CachedResponse
impl Clone for CachedResponse
Source§fn clone(&self) -> CachedResponse
fn clone(&self) -> CachedResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more