Struct kvarn::extensions::Extensions
source · pub struct Extensions { /* private fields */ }
Expand description
Contains all extensions. See kvarn.org on extensions for more info.
Implementations§
source§impl Extensions
impl Extensions
sourcepub fn with_disallow_cors(&mut self) -> &mut Self
pub fn with_disallow_cors(&mut self) -> &mut Self
Adds extensions to disallow all CORS requests.
This is added when calling Extensions::new
.
source§impl Extensions
impl Extensions
source§impl Extensions
impl Extensions
sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates a empty Extensions
.
It is strongly recommended to use Extensions::new()
instead.
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Extensions
and adds a few essential extensions.
For now the following extensions are added. The number in parentheses is the priority.
- A Prime extension (-64) redirecting the user from
<path>/
to<path>/index.html
and<path>.
to<path>.html
. This was earlier part of parsing of the path, but was moved to an extension for consistency and performance; now/
,index.
, andindex.html
is the same entity in cache. - A Package extension (8) to set
referrer-policy
header tono-referrer
for max security and privacy. This is only done when no otherreferrer-policy
header has been set earlier in the response. - A CORS extension to deny all CORS requests. See
Self::with_cors
for CORS management. - A nonce implementation for easy nonce setup. (requires
nonce
feature). - The default
Csp
which only allows requests fromself
and allows unsafe inline styles. This should to a large extent mitigate XSS. - The
server
header is set toKvarn/<version>
. SeeSelf::with_server_header
for more info and customization.
sourcepub fn with_uri_redirect(&mut self) -> &mut Self
pub fn with_uri_redirect(&mut self) -> &mut Self
Adds a prime extension to redirect Uri
s ending with .
and /
.
This routs the requests according to host::Options::folder_default
and
host::Options::extension_default
.
See respective documentation for more info.
sourcepub fn with_no_referrer(&mut self) -> &mut Self
pub fn with_no_referrer(&mut self) -> &mut Self
Adds a Package
extension to set the referrer-policy
to no-referrer
for maximum privacy and security.
If another referrer-policy
is already present, nothing happens.
This is added when calling Extensions::new
.
sourcepub fn with_http_to_https_redirect(&mut self) -> &mut Self
Available on crate feature https
only.
pub fn with_http_to_https_redirect(&mut self) -> &mut Self
https
only.Adds a Prepare
and a Prime
extension (with a priority of 86881
) which redirects requests using HTTP to HTTPS
with a StatusCode::TEMPORARY_REDIRECT
.
For more info about how it works, see the source of this function.
sourcepub fn with_nonce(&mut self) -> &mut Self
Available on crate feature nonce
only.
pub fn with_nonce(&mut self) -> &mut Self
nonce
only.Adds a Present
extension triggered by the internal extension nonce
which adds nonce
tags to all scripts with nonce=
tags.
You MUST NOT have server caching enabled.
This integrates with your csp
- if any nonce
extension is added, the corresponding
information is added to the content-security-policy
header.
See kvarn.org for more details.
sourcepub fn with_server_header(
&mut self,
server_name: impl AsRef<str>,
add_platform: bool,
override_server_header: bool
) -> &mut Self
pub fn with_server_header( &mut self, server_name: impl AsRef<str>, add_platform: bool, override_server_header: bool ) -> &mut Self
Set the server
header to server_name
.
This is called by default when creating a new Extensions
(except when calling
Extensions::empty
).
If add_platform
is true, append the platform the server is running
on to the end of the server header.
If override_server_header
is true, remove any previous mentions of the server software.
Set to false if you want reverse proxies to pass through the information (and therefore
return two server
headers to the user agent (maybe for debugging)).
In most cases, it should be set to true.
sourcepub fn remove_prime(&mut self, id: Id)
pub fn remove_prime(&mut self, id: Id)
Removes the Prime
extension (if any) with id
.
sourcepub fn add_prepare_single(&mut self, path: impl AsRef<str>, extension: Prepare)
pub fn add_prepare_single(&mut self, path: impl AsRef<str>, extension: Prepare)
Adds a Prepare
extension for a single URI.
sourcepub fn remove_prepare_single(&mut self, path: impl AsRef<str>)
pub fn remove_prepare_single(&mut self, path: impl AsRef<str>)
Removes the Prepare
extension (if any) at path
.
sourcepub fn get_prepare_single(&self) -> &HashMap<CompactString, Prepare>
pub fn get_prepare_single(&self) -> &HashMap<CompactString, Prepare>
Get a reference to the Prepare
extensions bound to a path.
sourcepub fn add_prepare_fn(&mut self, predicate: If, extension: Prepare, id: Id)
pub fn add_prepare_fn(&mut self, predicate: If, extension: Prepare, id: Id)
Adds a Prepare
extension run if function
return true
. Higher Id::priority()
extensions are ran first.
sourcepub fn remove_prepare_fn(&mut self, id: Id)
pub fn remove_prepare_fn(&mut self, id: Id)
Removes the Prepare
extension (if any) with id
.
sourcepub fn get_prepare_fn(&self) -> &[(Id, If, Prepare)]
pub fn get_prepare_fn(&self) -> &[(Id, If, Prepare)]
Get a reference to the Prepare
extensions using predicates.
sourcepub fn add_present_internal(
&mut self,
name: impl AsRef<str>,
extension: Present
)
pub fn add_present_internal( &mut self, name: impl AsRef<str>, extension: Present )
Adds a Present
internal extension, called with files starting with !>
.
sourcepub fn remove_present_internal(&mut self, path: impl AsRef<str>)
pub fn remove_present_internal(&mut self, path: impl AsRef<str>)
Removes the Present
internal extension (if any) at path
.
sourcepub fn get_present_internal(&self) -> &HashMap<CompactString, Present>
pub fn get_present_internal(&self) -> &HashMap<CompactString, Present>
Get a reference to the Present
internal extensions bound to a path.
sourcepub fn add_present_file(&mut self, name: impl AsRef<str>, extension: Present)
pub fn add_present_file(&mut self, name: impl AsRef<str>, extension: Present)
Adds a Present
file extension, called with file extensions matching name
.
sourcepub fn remove_present_file(&mut self, path: impl AsRef<str>)
pub fn remove_present_file(&mut self, path: impl AsRef<str>)
Removes the Present
file extension (if any) at path
.
sourcepub fn get_present_file(&self) -> &HashMap<CompactString, Present>
pub fn get_present_file(&self) -> &HashMap<CompactString, Present>
Get a reference to the Present
file extensions bound to a path.
sourcepub fn add_package(&mut self, extension: Package, id: Id)
pub fn add_package(&mut self, extension: Package, id: Id)
Adds a Package
extension, used to make last-minute changes to response. Higher Id::priority()
extensions are ran first.
sourcepub fn remove_package(&mut self, id: Id)
pub fn remove_package(&mut self, id: Id)
Removes the Package
extension (if any) with id
.
sourcepub fn get_package(&self) -> &[(Id, Package)]
pub fn get_package(&self) -> &[(Id, Package)]
Get a reference to the Package
extensions.
sourcepub fn add_post(&mut self, extension: Post, id: Id)
pub fn add_post(&mut self, extension: Post, id: Id)
Adds a Post
extension, used for HTTP/2 push Higher Id::priority()
extensions are ran first.
sourcepub fn remove_post(&mut self, id: Id)
pub fn remove_post(&mut self, id: Id)
Removes the Post
extension (if any) with id
.