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§

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.

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

Add cache headers to responses for the given lifespan.

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

Serve a request.

Examples found in repository?
src/service.rs (line 105)
104
105
106
    fn call(&mut self, request: Request<B>) -> Self::Future {
        Box::pin(self.clone().serve(request))
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Responses given by the service.
Errors produced by the service.
The future response value.
Process the request and return the response asynchronously.

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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