pub struct Resolver<O = TokioFileOpener> {
    pub opener: Arc<O>,
    pub allowed_encodings: AcceptEncoding,
}
Expand description

Resolves request paths to files.

This struct resolves files based on the request path. The path is first sanitized, then mapped to a file on the filesystem. If the path corresponds to a directory, it will try to look for a directory index.

Cloning this struct is a cheap operation.

Fields§

§opener: Arc<O>

The (virtual) filesystem used to open files.

§allowed_encodings: AcceptEncoding

Encodings the client is allowed to request with Accept-Encoding.

This only supports pre-encoded files, that exist adjacent to the original file, but with an additional .br or .gz suffix (after the original extension).

Typically initialized with AcceptEncoding::all() or AcceptEncoding::none().

Implementations§

source§

impl Resolver<TokioFileOpener>

source

pub fn new(root: impl Into<PathBuf>) -> Self

Create a resolver that resolves files inside a root directory on the regular filesystem.

source§

impl<O: FileOpener> Resolver<O>

source

pub fn with_opener(opener: O) -> Self

Create a resolver with a custom file opener.

source

pub async fn resolve_request<B>( &self, req: &Request<B> ) -> Result<ResolveResult<O::File>, IoError>

Resolve the request by trying to find the file in the root.

The returned future may error for unexpected IO errors, passing on the std::io::Error. Certain expected IO errors are handled, though, and simply reflected in the result. These are NotFound and PermissionDenied.

source

pub async fn resolve_path( &self, request_path: &str, accept_encoding: AcceptEncoding ) -> Result<ResolveResult<O::File>, IoError>

Resolve the request path by trying to find the file in the given root.

The returned future may error for unexpected IO errors, passing on the std::io::Error. Certain expected IO errors are handled, though, and simply reflected in the result. These are NotFound and PermissionDenied.

Note that, unlike resolve_request, it is up to the caller to check the request method and optionally the ‘Accept-Encoding’ header.

Trait Implementations§

source§

impl<O> Clone for Resolver<O>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<O> RefUnwindSafe for Resolver<O>where O: RefUnwindSafe,

§

impl<O> Send for Resolver<O>where O: Send + Sync,

§

impl<O> Sync for Resolver<O>where O: Send + Sync,

§

impl<O> Unpin for Resolver<O>

§

impl<O> UnwindSafe for Resolver<O>where O: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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>,

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.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
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.
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

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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