Struct hyper_staticfile::Static
source · 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>
impl Static<TokioFileOpener>
source§impl<O: FileOpener> Static<O>
impl<O: FileOpener> Static<O>
sourcepub fn with_opener(opener: O) -> Self
pub fn with_opener(opener: O) -> Self
Create a new instance of Static
with the given root directory.
sourcepub fn cache_headers(&mut self, value: Option<u32>) -> &mut Self
pub fn cache_headers(&mut self, value: Option<u32>) -> &mut Self
Add cache headers to responses for the given lifespan.
sourcepub fn allowed_encodings(
&mut self,
allowed_encodings: AcceptEncoding
) -> &mut Self
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.