pub struct Collection { /* private fields */ }
Expand description
A collection of Host
s, with an optional default and
arbitrarily many others, indexed by [Host.name
].
Tries to route to the host with it’s name.
If no host with a matching name is found, it’ll fall back to default
, if
that’s Some
.
When called from
localhost
, the first host added is always used.
If the feature https
is enabled, [rustls::server::ResolvesServerCert
] is implemented
using the pattern described above.
Implementations§
source§impl Collection
impl Collection
sourcepub fn builder() -> CollectionBuilder
pub fn builder() -> CollectionBuilder
Creates a new CollectionBuilder
with default_host
as the default.
sourcepub fn simple_non_secure(
default_host_name: impl AsRef<str>,
extensions: Extensions,
) -> Self
pub fn simple_non_secure( default_host_name: impl AsRef<str>, extensions: Extensions, ) -> Self
Creates a Host
without certification, using the directories ./public
and ./templates
.
The host is the default. See host
for more info.
sourcepub fn get_default(&self) -> Option<&Host>
pub fn get_default(&self) -> Option<&Host>
Returns a reference to the default Host
.
Use Self::get_from_request
to get the appropriate host.
sourcepub fn get_or_default(&self, name: &str) -> Option<&Host>
pub fn get_or_default(&self, name: &str) -> Option<&Host>
sourcepub fn get_option_or_default(&self, name: Option<&str>) -> Option<&Host>
pub fn get_option_or_default(&self, name: Option<&str>) -> Option<&Host>
Get a Host
by name, if any, and returns it or the default
if name
is None
or Self::get_or_default
returns None
.
sourcepub fn get_from_request<'a>(
&'a self,
request: &Request<Body>,
sni_hostname: Option<&str>,
) -> Option<&'a Host>
pub fn get_from_request<'a>( &'a self, request: &Request<Body>, sni_hostname: Option<&str>, ) -> Option<&'a Host>
Get the host depending on header::HOST
and the sni_hostname
.
sourcepub fn has_secure(&self) -> bool
pub fn has_secure(&self) -> bool
Returns if any Host
s are Host::is_secure
.
sourcepub fn make_config(self: &Arc<Self>) -> ServerConfig
Available on crate feature https
only.
pub fn make_config(self: &Arc<Self>) -> ServerConfig
https
only.Makes a [rustls::ServerConfig
] from Self
.
This takes Self
in an Arc
and clones it.
You should not have to call this, since PortDescriptor::new
and PortDescriptor::https
calls it internally.
Though, you could use the host
system by itself, without the rest of Kvarn.
sourcepub async fn clear_response_caches(&self, host_filter: Option<&str>)
pub async fn clear_response_caches(&self, host_filter: Option<&str>)
Clears all response caches.
sourcepub async fn clear_file_caches(&self, host_filter: Option<&str>)
pub async fn clear_file_caches(&self, host_filter: Option<&str>)
Clears all file caches.
sourcepub fn clear_file(&self, host: &str, path: impl AsRef<str>) -> (bool, bool)
pub fn clear_file(&self, host: &str, path: impl AsRef<str>) -> (bool, bool)
Clears a single path
in host
.
If host
is ""
or "default"
, the default host is used.
§Returns
(if host was found, cleared page)
This will probably become a error enum in the future.
It will never return (false, true).
This iterates over all caches and locks them, which takes a lot of time. Though, it’s not blocking.
Trait Implementations§
source§impl Debug for Collection
impl Debug for Collection
source§impl ResolvesServerCert for Collection
Available on crate feature https
only.
impl ResolvesServerCert for Collection
https
only.