pub struct Static<O = TokioFileOpener> {
    pub resolver: Resolver<O>,
    pub cache_headers: Option<u32>,
}
Expand description

High-level interface for serving static files.

This services serves 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.

This struct allows direct access to its fields, but these fields are typically initialized by the accessors, using the builder pattern. The fields are basically a bunch of settings that determine the response details.

This struct also implements the hyper::Service trait, which simply wraps Static::serve. Note that using the trait currently involves an extra Box.

Cloning this struct is a cheap operation.

Fields§

§resolver: Resolver<O>

The resolver instance used to open files.

§cache_headers: Option<u32>

Whether to send cache headers, and what lifespan to indicate.

Implementations§

source§

impl Static<TokioFileOpener>

source

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

Create a new instance of Static with a given root path.

The path may be absolute or relative. If Path::new("") is used, files will be served from the current directory.

source§

impl<O: FileOpener> Static<O>

source

pub fn with_opener(opener: O) -> Self

Create a new instance of Static with the given root directory.

source

pub fn cache_headers(&mut self, value: Option<u32>) -> &mut Self

Add cache headers to responses for the given lifespan.

source

pub fn allowed_encodings( &mut self, allowed_encodings: AcceptEncoding ) -> &mut Self

Set the encodings the client is allowed to request via the Accept-Encoding header.

source

pub async fn serve<B>( self, request: Request<B> ) -> Result<Response<Body<<O::File as IntoFileAccess>::Output>>, IoError>

Serve a request.

Trait Implementations§

source§

impl<O> Clone for Static<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
source§

impl<O, B> Service<Request<B>> for Static<O>where O: FileOpener, B: Send + Sync + 'static,

§

type Response = Response<Body<<<O as FileOpener>::File as IntoFileAccess>::Output>>

Responses given by the service.
§

type Error = Error

Errors produced by the service.
§

type Future = Pin<Box<dyn Future<Output = Result<<Static<O> as Service<Request<B>>>::Response, <Static<O> as Service<Request<B>>>::Error>> + Send>>

The future response value.
source§

fn call(&self, request: Request<B>) -> Self::Future

Process the request and return the response asynchronously. call takes a &self instead of a mut &self because: Read more

Auto Trait Implementations§

§

impl<O = TokioFileOpener> !RefUnwindSafe for Static<O>

§

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

§

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

§

impl<O> Unpin for Static<O>

§

impl<O = TokioFileOpener> !UnwindSafe for Static<O>

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, B1, B2> HttpService<B1> for Twhere T: Service<Request<B1>, Response = Response<B2>>, B2: Body, <T as Service<Request<B1>>>::Error: Into<Box<dyn Error + Send + Sync>>,

§

type ResBody = B2

The Body body of the http::Response.
§

type Error = <T as Service<Request<B1>>>::Error

The error type that can occur within this Service. Read more
§

type Future = <T as Service<Request<B1>>>::Future

The Future returned by this Service.
source§

fn call(&mut self, req: Request<B1>) -> <T as HttpService<B1>>::Future

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