logo
pub struct Extensions { /* private fields */ }
Expand description

Contains all extensions. See kvarn.org on extensions for more info.

Implementations

Adds extensions to disallow all CORS requests. This is added when calling Extensions::new.

Overrides the default handling (deny all) of CORS requests to be cors_settings.

See Cors for an example and more info.

Sets the set of rules to handle CSP.

Creates a empty Extensions.

It is strongly recommended to use Extensions::new() instead.

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., and index.html is the same entity in cache.
  • A Package extension (8) to set referrer-policy header to no-referrer for max security and privacy. This is only done when no other referrer-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 from self and allows unsafe inline styles. This should to a large extent mitigate XSS.

Adds a prime extension to redirect Uris ending with . and /.

This routs the requests according to host::Options::folder_default and host::Options::extension_default. See respective documentation for more info.

Adds a Package extension to set the referrer-policy to no-referrer for maximum privacy and security. This is added when calling Extensions::new.

Available on crate feature https only.

Adds a Prepare and a Prime extension (with a priority of 4) 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.

Available on crate feature 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.

Adds a Prime extension.

Removes the Prime extension (if any) with id.

Get a reference to the Prime extensions.

Adds a Prepare extension for a single URI.

Removes the Prepare extension (if any) at path.

Get a reference to the Prepare extensions bound to a path.

Adds a Prepare extension run if function return true. Higher Id::priority() extensions are ran first.

Removes the Prepare extension (if any) with id.

Get a reference to the Prepare extensions using predicates.

Adds a Present internal extension, called with files starting with !> .

Removes the Present internal extension (if any) at path.

Get a reference to the Present internal extensions bound to a path.

Adds a Present file extension, called with file extensions matching name.

Removes the Present file extension (if any) at path.

Get a reference to the Present file extensions bound to a path.

Adds a Package extension, used to make last-minute changes to response. Higher Id::priority() extensions are ran first.

Removes the Package extension (if any) with id.

Get a reference to the Package extensions.

source

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.

source

pub fn remove_post(&mut self, id: Id)

Removes the Post extension (if any) with id.

source

pub fn get_post(&self) -> &[(Id, Post)]

Get a reference to the Package extensions.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more