Backend
pub struct Backend { /* private fields */ }A named backend.
This represents a backend associated with a service that we can send requests to, potentially caching the responses received.
Backends come in one of two flavors:
- Static Backends: These backends are created using the Fastly UI or API,
and are predefined by the user. Static backends have short names (see the
precise naming rules in
Backend::from_name) that are usable across every session of a service. - Dynamic Backends: These backends are created programmatically using the
Backend::builderAPI. They are defined at runtime, and may or may not be shared across sessions depending on how they are configured.
To use a backend, pass it to the crate::Request::send method. Alternatively, the following
values can be automatically coerced into a backend for you, without the need to explicitly
create a Backend object, although they may all induce panics:
- Any string type (
&str,String, or&String) will be automatically turned into the static backend of the same name.
Using Static Backends
As stated at the top level, the following snippet is a minimal program that resends a request to a static backend named "example_backend":
use fastly::{Error, Request, Response};
#[fastly::main]fn main(ds_req: Request) -> Result<Response, Error> { Ok(ds_req.send("example_backend")?)}A safer alternative to this example would be the following:
123456789101112use fastly::{Backend, Error, Request, Response};
#[fastly::main]fn main(ds_req: Request) -> Result<Response, Error> { match Backend::from_name("example_backend") { Ok(backend) => Ok(ds_req.send(backend)?), Err(_) => { // custom backend failure response unimplemented!() } }}as this version allows you to handle backend errors more cleanly.
Validating Support for Dynamic Backends
Since dynamic backends are only enabled for some services, it may be particularly
useful to ensure that dynamic backends are supported in your Compute service.
The easiest way to do so is to try to create a dynamic backend, and then explicitly
check for the crate::backend::BackendCreationError::Disallowed code, as follows:
1234567891011121314151617use fastly::{Backend, Error, Request, Response};use fastly::backend::BackendCreationError;
#[fastly::main]fn main(ds_req: Request) -> Result<Response, Error> { match Backend::builder("custom_backend", "example.org:993").finish() { Ok(backend) => Ok(ds_req.send(backend)?), Err(BackendCreationError::Disallowed) => { // custom code ofr handling when dynamic backends aren't supported unimplemented!() } Err(err) => { // more specific logging/handling for backend misconfigurations unimplemented!() } }}Methods
builder
View sourceCreate a new dynamic backend builder.
The arguments are the name of the new backend to use, along with a string describing the backend host. The latter can be of the form:
"<ip address>""<hostname>""<ip address>:<port>""<hostname>:<port>"
The name can be whatever you would like, as long as it does not match the name of any of the static service backends nor match any other dynamic backends built during this session. (Names can overlap between different sessions of the same service -- they will be treated as completely separate entities and will not be pooled -- but you cannot, for example, declare a dynamic backend named "dynamic-backend" twice in the same session.)
The builder will start with default values for all other possible fields for the
backend, which can be overridden using the other methods provided. Call
finish() to complete the construction of the dynamic backend.
Dynamic backends must be enabled for this Compute service. You can determine
whether or not dynamic backends have been allowed for the current service by
using this builder, and then checking for the BackendCreationError::Disallowed
error result. This error only arises when attempting to use dynamic backends
with a service that has not had dynamic backends enabled, or dynamic backends
have been administratively prohibited for the node in response to an ongoing
incident.
Parameters
Returns
exists
View sourcefn exists(&self) -> boolReturns true if a backend with this name exists.
Parameters
- self: &Self
Returns
from_name
View sourceGet a backend by its name.
This function will return a BackendError if an invalid name was given.
Backend names:
- cannot be empty
- cannot be longer than 255 characters
- cannot ASCII control characters such as
'\n'orDELETE. - cannot contain special Unicode characters
- should only contain visible ASCII characters or spaces
Future versions of this function may return an error if your service does not have a backend with this name.
Parameters
- s: &str
Returns
get_between_bytes_timeout
View sourcefn get_between_bytes_timeout(&self) -> DurationReturns the "between bytes" timeout for this backend.
This timeout applies between any two bytes we receive across the wire.
Use
BackendBuilder::between_bytes_timeout
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_connect_timeout
View sourcefn get_connect_timeout(&self) -> DurationReturns the connection timeout for this backend.
Use
BackendBuilder::connect_timeout
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_first_byte_timeout
View sourcefn get_first_byte_timeout(&self) -> DurationReturns the "first byte" timeout for this backend.
This timeout applies between the time of connection and the time we get the first byte back.
Use
BackendBuilder::first_byte_timeout
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_host_override
View sourceReturns the host header override when contacting this backend.
This method returns None if no host header override is configured for this backend.
This is used to change the Host header sent to the backend. For more information, see
the Fastly documentation on host overrides here:
https://docs.fastly.com/en/guides/specifying-an-override-host
Use
BackendBuilder::override_host
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_http_keepalive_time
View sourcefn get_http_keepalive_time(&self) -> DurationReturns the time to hold onto an idle HTTP keepalive connection after it was last used before closing it.
Use
BackendBuilder::http_keepalive_time
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_ssl_max_version
View sourceReturns the maximum TLS version for connecting to the backend.
This method returns None if SSL/TLS is not enabled for this backend.
Use
BackendBuilder::set_max_tls_version
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_ssl_min_version
View sourceReturns the minimum TLS version for connecting to the backend.
This method returns None if SSL/TLS is not enabled for this backend.
Use
BackendBuilder::set_min_tls_version
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_tcp_keepalive_enable
View sourcefn get_tcp_keepalive_enable(&self) -> boolReturns true if TCP keepalives have been enabled for this backend.
Use
BackendBuilder::tcp_keepalive_enable
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_tcp_keepalive_interval
View sourcefn get_tcp_keepalive_interval(&self) -> DurationReturns the time to wait in between sending each TCP keepalive probe to this backend.
Use
BackendBuilder::tcp_keepalive_interval_secs
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_tcp_keepalive_probes
View sourcefn get_tcp_keepalive_probes(&self) -> u32Returns the time to wait after the last data was sent before starting to send TCP keepalive probes to this backend.
Use
BackendBuilder::tcp_keepalive_probes
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
get_tcp_keepalive_time
View sourcefn get_tcp_keepalive_time(&self) -> DurationReturns the time to wait after the last data was sent before starting to send TCP keepalive probes to this backend.
Use
BackendBuilder::tcp_keepalive_time_secs
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
healthcheck_builder
View sourceCreate a new health check builder for a dynamic backend.
The argument is a string describing the backend host on which to check health checks on. This can be of the form:
"<ip address>""<hostname>""<ip address>:<port>""<hostname>:<port>"
The builder will start with default values for all other possible fields for the
health check, which can be overridden using the other methods provided. Use
BackendBuilder::healthcheck to add the health check to a specific Dynamic Backend
and call BackendBuilder::finish() to complete the construction of the dynamic backend.
Values for health checks have strict limits to prevent ill-use. If you create a health
check with a value that breaks these limits, finish() will error with a
BackendCreationError:InvalidHealthcheckValues
Parameters
- host: impl ToString
Returns
into_string
View sourcefn into_string(self) -> StringTurn the backend into its name as a string.
Parameters
- self: Self
Returns
is_ssl
View sourcefn is_ssl(&self) -> boolReturns true if SSL/TLS is used to connect to the backend.
Use
BackendBuilder::enable_ssl or
BackendBuilder::disable_ssl
to set this for a dynamic backend.
Panics
If the name() of this backend does not match any of the backends associated
with this service, this function will panic. Use exists() to explicitly
check that this backend exists.
Parameters
- self: &Self
Returns
Trait implementations
impl BackendExt for Backend
impl Clone for Backend
impl Debug for Backend
impl Display for Backend
impl FromStr for Backend
impl Hash for Backend
impl Ord for Backend
cmp
View sourcefn cmp(&self, other: &Self) -> OrderingParameters
- self: &Self
- other: &Self
Returns