CandidateResponse
pub struct CandidateResponse { /* private fields */ }A response from a backend that is a candidate for caching.
Methods
append_header
View sourceAdd a response header with given value.
Unlike set_header(), this does not discard existing values for the
same header name.
Argument type conversion
The header name and value arguments can be any types that implement ToHeaderName and
ToHeaderValue, respectively. See those traits for details on which types can be used and when
panics may arise during conversion.
Examples
Parameters
- self: &mut Self
- name: impl ToHeaderName
- value: impl ToHeaderValue
append_vary
View sourceAdds zero or more headers to the set of request headers for which the response may vary.
Parameters
- self: &mut Self
- headers: impl IntoIterator<Item = &'a HeaderName>
contains_header
View sourceReturns whether the given header name is present in the response.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Examples
Parameters
- self: &Self
- name: impl ToHeaderName
Returns
get_age
View sourcefn get_age(&self) -> DurationThe current age of the cached item, relative to the originating backend.
Parameters
- self: &Self
Returns
get_content_length
View sourceGet the value of the response's
Content-Length
header, if it exists.
Parameters
- self: &Self
Returns
get_content_type
View sourceGet the MIME type described by the response's
Content-Type
header, or None if that header is absent or contains an invalid MIME type.
Examples
Parameters
- self: &Self
Returns
get_header
View sourceGet the value of a header, or None if the header is not present.
If there are multiple values for the header, only one is returned, which may be any of the
values. See get_header_all() if you need to get all of the
values.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Examples
See Response::get_header.
Parameters
- self: &Self
- name: impl ToHeaderName
Returns
get_header_all
View sourceGet an iterator of all the values of a header.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Examples
Parameters
- self: &Self
- name: impl ToHeaderName
Returns
get_header_all_str
View sourceGet all values of a header as strings, or an empty vector if the header is not present.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Panics
This method panics if any of the header values are not valid UTF-8 strings. To handle the
possibility of non-UTF-8 data, use
get_header_all_str_lossy() for lossy conversion, or use
get_header_all() and then convert the bytes with
std::str::from_utf8().
Examples
Parameters
- self: &Self
- name: impl ToHeaderName
Returns
get_header_all_str_lossy
View sourceGet all values of a header as strings, including invalid characters, or an empty vector if the header is not present.
Only the valid UTF-8 characters present are returned.
Invalid UTF-8 characters are replaced with U+FFFD REPLACEMENT CHARACTER.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Examples
Parameters
- self: &Self
- name: impl ToHeaderName
Returns
get_header_names_str
View sourceGet all of the response's header names as strings, or an empty vector if no headers are present.
Examples
Parameters
- self: &Self
Returns
get_header_str
View sourceGet the value of a header as a string, or None if the header is not present.
If there are multiple values for the header, only one is returned, which may be any of the
values. See get_header_all_str() if you need to get all of
the values.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Panics
This method panics if the value of the header is not a valid UTF-8 string. To handle the possibility
of invalid UTF-8 data, use get_header_str_lossy() for lossy
conversion, or use get_header() and then convert the bytes with
std::str::from_utf8().
Examples
Parameters
- self: &Self
- name: impl ToHeaderName
Returns
get_header_str_lossy
View sourceGet the value of a header as a string, including invalid characters, or None if the header
is not present.
Only the valid UTF-8 characters present are returned.
Invalid UTF-8 characters are replaced with U+FFFD REPLACEMENT CHARACTER.
If there are multiple values for the header, only one is returned, which may be any of the
values. See get_header_all_str_lossy() if you need
to get all of the values.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Examples
Parameters
- self: &Self
- name: impl ToHeaderName
Returns
get_stale_if_error
View sourcefn get_stale_if_error(&self) -> DurationGets the time for which a cached item can safely be used if (synchronous) revalidation produces an error.
Parameters
- self: &Self
Returns
get_stale_while_revalidate
View sourcefn get_stale_while_revalidate(&self) -> DurationGets the time for which a cached item can safely be used despite being considered stale.
Parameters
- self: &Self
Returns
get_status
View sourcefn get_status(&self) -> StatusCodeGet the HTTP status code of the response.
Parameters
- self: &Self
Returns
get_surrogate_keys
View sourceGets the surrogate keys for the cached response.
Parameters
- self: &Self
Returns
get_ttl
View sourcefn get_ttl(&self) -> DurationGet the Time to Live (TTL) in the cache for this response.
The TTL determines the duration of "freshness" for the cached response after it is inserted into the cache.
Parameters
- self: &Self
Returns
get_vary
View sourceGets the set of request headers for which the response may vary.
Parameters
- self: &Self
Returns
get_version
View sourcefn get_version(&self) -> VersionGet the HTTP version of this response.
Parameters
- self: &Self
Returns
is_cacheable
View sourcefn is_cacheable(&self) -> boolGets whether this response should be cached.
Parameters
- self: &Self
Returns
is_sensitive_data
View sourcefn is_sensitive_data(&self) -> boolGets whether this response should only be stored via PCI/HIPAA-compliant non-volatile caching.
See the Fastly PCI-Compliant Caching and Delivery documentation for details.
Parameters
- self: &Self
Returns
is_stale
View sourcefn is_stale(&self) -> boolDetermines whether the cached response is stale.
A cached response is stale if it has been in the cache beyond its TTL period, or if it has been soft purged.
Parameters
- self: &Self
Returns
push_vary
View sourceAdds a header to the set of request headers for which the response may vary.
Parameters
- self: &mut Self
- header: &HeaderName
remove_header
View sourceRemove all response headers of the given name, and return one of the removed header values if any were present.
If the header has multiple values, one is returned arbitrarily. To get all of the removed
header values, or to get a specific value, use
get_header_all().
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Examples
Parameters
- self: &mut Self
- name: impl ToHeaderName
Returns
remove_header_str
View sourceRemove all response headers of the given name, and return one of the removed header values as a string if any were present.
If the header has multiple values, one is returned arbitrarily. To get all of the removed header
values, use get_header_all() before removing.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Panics
This method panics if the value of the header is not a valid UTF-8 string. To handle the possibility
of invalid UTF-8 data, use remove_header_str_lossy() for lossy
conversion, or use remove_header() and then convert the bytes with
std::str::from_utf8().
Examples
Parameters
- self: &mut Self
- name: impl ToHeaderName
Returns
remove_header_str_lossy
View sourceRemove all response headers of the given name, and return one of the removed header values as a string, including invalid characters, if any were present.
Only the valid UTF-8 characters present are returned.
Invalid UTF-8 characters are replaced with U+FFFD REPLACEMENT CHARACTER.
If the header has multiple values, one is returned arbitrarily. To get all of the removed header
values, use get_header_all() before removing.
Argument type conversion
The header name argument can be any type that implements ToHeaderName; see that trait for
details on which types can be used and when panics may arise during conversion.
Examples
Parameters
- self: &mut Self
- name: impl ToHeaderName
Returns
set_body_transform
View sourcefn set_body_transform(&mut self, transform: impl FnOnce(Body, &mut StreamingBody) -> Result<(), SendErrorCause> + 'static)Sets a callback to be used for transforming the response body prior to caching.
Body transformations are performed via a callback, rather than by directly working with the body, because not every response contains a fresh body: 304 Not Modified responses, which are used to revalidate a stale cached response, are valuable precisely because they do not retransmit the body.
For any other response status, the backend response will contain a
relevant body, and the transform callback will be invoked. The
original backend body of type Body is given as the first parameter to
the transform. The transform is responsible for writing the new body
into the StreamingBody given as its second argument. Upon returning from
the transform, StreamingBody::finish() will be called implicitly. This
setup allows the transform to work with streamed chunks of the backend body,
rather than necessarily reading it entirely into memory.
Parameters
- self: &mut Self
- transform: impl FnOnce(Body, &mut StreamingBody) -> Result<(), SendErrorCause> + 'static
set_cacheable
View sourcefn set_cacheable(&mut self)Forces this response to be stored in the cache, even if its headers or status would normally prevent that.
Parameters
- self: &mut Self
set_content_type
View sourceSet the MIME type described by the response's
Content-Type
header.
Any existing Content-Type header values will be overwritten.
Examples
Parameters
- self: &mut Self
- mime: Mime
set_header
View sourceSet a response header to the given value, discarding any previous values for the given header name.
Argument type conversion
The header name and value arguments can be any types that implement ToHeaderName and
ToHeaderValue, respectively. See those traits for details on which types can be used and when
panics may arise during conversion.
Examples
See Response::set_header.
Parameters
- self: &mut Self
- name: impl ToHeaderName
- value: impl ToHeaderValue
set_sensitive_data
View sourcefn set_sensitive_data(&mut self, is_sensitive_data: bool)Set the caching behavior of this response to enable or disable PCI/HIPAA-compliant non-volatile caching.
By default, this is false, which means the response may not be PCI/HIPAA-compliant. Set it
to true to enable compliant caching.
See the Fastly PCI-Compliant Caching and Delivery documentation for details.
Parameters
- self: &mut Self
- is_sensitive_data: bool
set_stale_if_error
View sourceSets the time for which a cached item can safely be used if (synchronous) revalidation produces an error.
Parameters
- self: &mut Self
- stale_if_error: Duration
set_stale_while_revalidate
View sourceSets the time for which a cached item can safely be used despite being considered stale.
Parameters
- self: &mut Self
- stale_while_revalidate: Duration
set_status
View sourceSet the HTTP status code of the response.
Argument type conversion
The status code argument can be any type that implements ToStatusCode; see that trait for
details on which types can be used and when panics may arise during conversion.
Examples
See Response::set_status.
Parameters
- self: &mut Self
- status: impl ToStatusCode
set_surrogate_keys
View sourceSets the surrogate keys for the cached response.
Surrogate keys must contain only printable ASCII characters (those between 0x21 and
0x7E, inclusive). Any invalid keys will be ignored.
See the Fastly surrogate keys guide for details.
Parameters
- self: &mut Self
- keys: impl IntoIterator<Item = &'a str>
set_ttl
View sourceSet the Time to Live (TTL) in the cache for this response.
The TTL determines the duration of "freshness" for the cached response after it is inserted into the cache.
Parameters
- self: &mut Self
- ttl: Duration
set_uncacheable
View sourcefn set_uncacheable(&mut self, record_uncacheable: bool)Set the response to not be stored in the cache.
Optionally, if record_uncacheable is true, the cache will record that
the originating request led to an uncacheable response, so that future
cache lookups will result in immediately going to the backend, rather
than attempting to coordinate concurrent requests to reduce backend
traffic.
See the Fastly request collapsing
guide
for more details on the mechanism that record_uncacheable disables.
Parameters
- self: &mut Self
- record_uncacheable: bool
set_vary
View sourceSets the set of request headers for which the response may vary.
Parameters
- self: &mut Self
- headers: impl IntoIterator<Item = &'a HeaderName>
set_version
View sourceSet the HTTP version of this response.
Parameters
- self: &mut Self
- version: Version
stale_if_error_available
View sourcefn stale_if_error_available(&self) -> boolReturns true if there is a stale-if-error response available from the cache.
A CandidateResponse represents an HTTP response returned from a Backend. However, it may be preferable to return a cached response rather than the Backend's response -- for instance, if the Backend's response is a 5xx error.
This method returns true if there is a cached response that is within the stale-if-error period. If a stale-if-error response is available, and the after_send hook returns an error, the response from the Backend will not be cached, and the Request::send call will return the stale-if-error response.
Parameters
- self: &Self
Returns
with_cacheable
View sourcefn with_cacheable(self, is_cacheable: bool, record_uncacheable: bool) -> SelfBuilder-style equivalent of set_cacheable()
and set_uncacheable()
Parameters
- self: Self
- is_cacheable: bool
- record_uncacheable: bool
Returns
with_content_type
View sourceBuilder-style equivalent of set_content_type().
Parameters
- self: Self
- mime: Mime
Returns
with_header
View sourceBuilder-style equivalent of append_header().
Parameters
- self: Self
- name: impl ToHeaderName
- value: impl ToHeaderValue
Returns
with_sensitive_data
View sourcefn with_sensitive_data(self, is_sensitive_data: bool) -> SelfBuilder-style equivalent of set_sensitive_data().
Parameters
- self: Self
- is_sensitive_data: bool
Returns
with_set_header
View sourceBuilder-style equivalent of set_header().
Parameters
- self: Self
- name: impl ToHeaderName
- value: impl ToHeaderValue
Returns
with_stale_while_revalidate
View sourceBuilder-style equivalent of set_stale_while_revalidate().
Parameters
- self: Self
- stale_while_revalidate: Duration
Returns
with_status
View sourceBuilder-style equivalent of set_status().
Parameters
- self: Self
- status: impl ToStatusCode
Returns
with_surrogate_keys
View sourceBuilder-style equivalent of set_surrogate_keys().
Parameters
- self: Self
- keys: impl IntoIterator<Item = &'a str>
Returns
with_ttl
View sourceBuilder-style equivalent of set_ttl().
Parameters
- self: Self
- ttl: Duration
Returns
with_vary
View sourceBuilder-style equivalent of set_vary().
Parameters
- self: Self
- headers: impl IntoIterator<Item = &'a HeaderName>
Returns
with_version
View sourceBuilder-style equivalent of set_version().
Parameters
- self: Self
- version: Version
Returns