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

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

Implementations§

source§

impl Extensions

source

pub fn with_disallow_cors(&mut self) -> &mut Self

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

source

pub fn with_cors(&mut self, cors_settings: Arc<Cors>) -> &mut Self

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

See Cors for an example and more info.

source§

impl Extensions

source

pub fn with_csp(&mut self, csp: Arc<Csp>) -> &mut Self

Sets the set of rules to handle CSP.

source§

impl Extensions

source

pub fn empty() -> Self

Creates a empty Extensions.

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

source

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., 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.
  • The server header is set to Kvarn/<version>. See Self::with_server_header for more info and customization.
source

pub fn with_uri_redirect(&mut self) -> &mut Self

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.

source

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.

source

pub fn with_http_to_https_redirect(&mut self) -> &mut Self

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

source

pub fn with_nonce(&mut self) -> &mut Self

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.

source

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.

source

pub fn add_prime(&mut self, extension: Prime, id: Id)

Adds a Prime extension.

source

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

Removes the Prime extension (if any) with id.

source

pub fn get_prime(&self) -> &[(Id, Prime)]

Get a reference to the Prime extensions.

source

pub fn add_prepare_single(&mut self, path: impl AsRef<str>, extension: Prepare)

Adds a Prepare extension for a single URI.

source

pub fn remove_prepare_single(&mut self, path: impl AsRef<str>)

Removes the Prepare extension (if any) at path.

source

pub fn get_prepare_single(&self) -> &HashMap<CompactString, Prepare>

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

source

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.

source

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

Removes the Prepare extension (if any) with id.

source

pub fn get_prepare_fn(&self) -> &[(Id, If, Prepare)]

Get a reference to the Prepare extensions using predicates.

source

pub fn add_present_internal( &mut self, name: impl AsRef<str>, extension: Present )

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

source

pub fn remove_present_internal(&mut self, path: impl AsRef<str>)

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

source

pub fn get_present_internal(&self) -> &HashMap<CompactString, Present>

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

source

pub fn add_present_file(&mut self, name: impl AsRef<str>, extension: Present)

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

source

pub fn remove_present_file(&mut self, path: impl AsRef<str>)

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

source

pub fn get_present_file(&self) -> &HashMap<CompactString, Present>

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

source

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.

source

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

Removes the Package extension (if any) with id.

source

pub fn get_package(&self) -> &[(Id, Package)]

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§

source§

impl Debug for Extensions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Extensions

source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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