CandidateResponse

Structin httpfastly 0.13.1View source
pub struct CandidateResponse { /* private fields */ }

A response from a backend that is a candidate for caching.

Methods

append_header

View source
fn append_header(&mut self, name: impl ToHeaderName, value: impl ToHeaderValue)

Add 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

See Response::append_header.

Parameters

self: &mut Self
name: impl ToHeaderName
value: impl ToHeaderValue

append_vary

View source
fn append_vary<'a>(&mut self, headers: impl IntoIterator<Item = &'a HeaderName>)

Adds 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 source
fn contains_header(&self, name: impl ToHeaderName) -> bool

Returns 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

See Response::contains_header.

Parameters

self: &Self
name: impl ToHeaderName

Returns

bool
fn get_age(&self) -> Duration

The current age of the cached item, relative to the originating backend.

Parameters

self: &Self

Returns

get_content_length

View source
fn get_content_length(&self) -> Option<usize>

Get the value of the response's Content-Length header, if it exists.

Parameters

self: &Self

Returns

Option<usize>

get_content_type

View source
fn get_content_type(&self) -> Option<Mime>

Get 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

See Response::get_content_type.

Parameters

self: &Self

Returns

get_header

View source
fn get_header(&self, name: impl ToHeaderName) -> Option<&HeaderValue>

Get 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 source
fn get_header_all(&self, name: impl ToHeaderName) -> impl Iterator<Item = &HeaderValue>

Get 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

See Response::get_header_all.

Parameters

self: &Self
name: impl ToHeaderName

Returns

impl Iterator<Item = &HeaderValue>

get_header_all_str

View source
fn get_header_all_str(&self, name: impl ToHeaderName) -> Vec<&str>

Get 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

See Response::get_header_all_str.

Parameters

self: &Self
name: impl ToHeaderName

Returns

Vec<&str>

get_header_all_str_lossy

View source
fn get_header_all_str_lossy(&self, name: impl ToHeaderName) -> Vec<Cow<'_, str>>

Get 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

See Response::get_header_all_str_lossy.

Parameters

self: &Self
name: impl ToHeaderName

Returns

Vec<Cow<str>>

get_header_names

View source
fn get_header_names(&self) -> impl Iterator<Item = &HeaderName>

Get an iterator of all the response's header names.

Examples

See Response::get_header_names.

Parameters

self: &Self

Returns

impl Iterator<Item = &HeaderName>

get_header_names_str

View source
fn get_header_names_str(&self) -> Vec<&str>

Get all of the response's header names as strings, or an empty vector if no headers are present.

Examples

See Response::get_header_names_str.

Parameters

self: &Self

Returns

Vec<&str>

get_header_str

View source
fn get_header_str(&self, name: impl ToHeaderName) -> Option<&str>

Get 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

See Response::get_header_str.

Parameters

self: &Self
name: impl ToHeaderName

Returns

Option<&str>

get_header_str_lossy

View source
fn get_header_str_lossy(&self, name: impl ToHeaderName) -> Option<Cow<'_, str>>

Get 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

See Response::get_header_str_lossy.

Parameters

self: &Self
name: impl ToHeaderName

Returns

Option<Cow<str>>

get_headers

View source
fn get_headers(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>

Get an iterator of all the response's header names and values.

Examples

See Response::get_headers.

Parameters

self: &Self

Returns

impl Iterator<Item = (&HeaderName, &HeaderValue)>

get_stale_if_error

View source
fn get_stale_if_error(&self) -> Duration

Gets 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 source
fn get_stale_while_revalidate(&self) -> Duration

Gets the time for which a cached item can safely be used despite being considered stale.

Parameters

self: &Self

Returns

get_status

View source
fn get_status(&self) -> StatusCode

Get the HTTP status code of the response.

Parameters

self: &Self

Returns

get_surrogate_keys

View source
fn get_surrogate_keys(&self) -> impl Iterator<Item = &str>

Gets the surrogate keys for the cached response.

Parameters

self: &Self

Returns

impl Iterator<Item = &str>
fn get_ttl(&self) -> Duration

Get 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 source
fn get_vary(&self) -> impl Iterator<Item = &str>

Gets the set of request headers for which the response may vary.

Parameters

self: &Self

Returns

impl Iterator<Item = &str>

get_version

View source
fn get_version(&self) -> Version

Get the HTTP version of this response.

Parameters

self: &Self

Returns

is_cacheable

View source
fn is_cacheable(&self) -> bool

Gets whether this response should be cached.

Parameters

self: &Self

Returns

bool

is_sensitive_data

View source
fn is_sensitive_data(&self) -> bool

Gets 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

bool

is_stale

View source
fn is_stale(&self) -> bool

Determines 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

bool

push_vary

View source
fn push_vary(&mut self, header: &HeaderName)

Adds a header to the set of request headers for which the response may vary.

Parameters

self: &mut Self
header: &HeaderName

remove_header

View source
fn remove_header(&mut self, name: impl ToHeaderName) -> Option<HeaderValue>

Remove 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

See Response::remove_header.

Parameters

self: &mut Self
name: impl ToHeaderName

Returns

remove_header_str

View source
fn remove_header_str(&mut self, name: impl ToHeaderName) -> Option<String>

Remove 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

See Response::remove_header_str.

Parameters

self: &mut Self
name: impl ToHeaderName

Returns

Option<String>

remove_header_str_lossy

View source
fn remove_header_str_lossy(&mut self, name: impl ToHeaderName) -> Option<String>

Remove 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

See Response::remove_header_str_lossy.

Parameters

self: &mut Self
name: impl ToHeaderName

Returns

Option<String>

set_body_transform

View source
fn 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 source
fn 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 source
fn set_content_type(&mut self, mime: Mime)

Set the MIME type described by the response's Content-Type header.

Any existing Content-Type header values will be overwritten.

Examples

See Response::set_content_type.

Parameters

self: &mut Self
mime: Mime

set_header

View source
fn set_header(&mut self, name: impl ToHeaderName, value: impl ToHeaderValue)

Set 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 source
fn 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 source
fn set_stale_if_error(&mut self, stale_if_error: Duration)

Sets 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 source
fn set_stale_while_revalidate(&mut self, stale_while_revalidate: Duration)

Sets 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 source
fn set_status(&mut self, status: impl ToStatusCode)

Set 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 source
fn set_surrogate_keys<'a>(&mut self, keys: impl IntoIterator<Item = &'a str>)

Sets 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>
fn set_ttl(&mut self, ttl: Duration)

Set 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 source
fn 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 source
fn set_vary<'a>(&mut self, headers: impl IntoIterator<Item = &'a HeaderName>)

Sets the set of request headers for which the response may vary.

Parameters

self: &mut Self
headers: impl IntoIterator<Item = &'a HeaderName>

set_version

View source
fn set_version(&mut self, version: Version)

Set the HTTP version of this response.

Parameters

self: &mut Self
version: Version

stale_if_error_available

View source
fn stale_if_error_available(&self) -> bool

Returns 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

bool

with_cacheable

View source
fn with_cacheable(self, is_cacheable: bool, record_uncacheable: bool) -> Self

Builder-style equivalent of set_cacheable() and set_uncacheable()

Parameters

self: Self
is_cacheable: bool
record_uncacheable: bool

Returns

Self

with_content_type

View source
fn with_content_type(self, mime: Mime) -> Self

Builder-style equivalent of set_content_type().

Parameters

self: Self
mime: Mime

Returns

Self

with_header

View source
fn with_header(self, name: impl ToHeaderName, value: impl ToHeaderValue) -> Self

Builder-style equivalent of append_header().

Parameters

self: Self
name: impl ToHeaderName
value: impl ToHeaderValue

Returns

Self

with_sensitive_data

View source
fn with_sensitive_data(self, is_sensitive_data: bool) -> Self

Builder-style equivalent of set_sensitive_data().

Parameters

self: Self
is_sensitive_data: bool

Returns

Self

with_set_header

View source
fn with_set_header(self, name: impl ToHeaderName, value: impl ToHeaderValue) -> Self

Builder-style equivalent of set_header().

Parameters

self: Self
name: impl ToHeaderName
value: impl ToHeaderValue

Returns

Self

with_stale_while_revalidate

View source
fn with_stale_while_revalidate(self, stale_while_revalidate: Duration) -> Self

Builder-style equivalent of set_stale_while_revalidate().

Parameters

self: Self
stale_while_revalidate: Duration

Returns

Self

with_status

View source
fn with_status(self, status: impl ToStatusCode) -> Self

Builder-style equivalent of set_status().

Parameters

self: Self
status: impl ToStatusCode

Returns

Self

with_surrogate_keys

View source
fn with_surrogate_keys<'a>(self, keys: impl IntoIterator<Item = &'a str>) -> Self

Builder-style equivalent of set_surrogate_keys().

Parameters

self: Self
keys: impl IntoIterator<Item = &'a str>

Returns

Self

with_ttl

View source
fn with_ttl(self, ttl: Duration) -> Self

Builder-style equivalent of set_ttl().

Parameters

self: Self
ttl: Duration

Returns

Self

with_vary

View source
fn with_vary<'a>(self, headers: impl IntoIterator<Item = &'a HeaderName>) -> Self

Builder-style equivalent of set_vary().

Parameters

self: Self
headers: impl IntoIterator<Item = &'a HeaderName>

Returns

Self

with_version

View source
fn with_version(self, version: Version) -> Self

Builder-style equivalent of set_version().

Parameters

self: Self
version: Version

Returns

Self

Auto trait implementations

Blanket implementations