Struct hyper_staticfile::Static
source · [−]Expand description
High-level interface for serving static files.
This struct serves files from a single root path, which may be absolute or relative. The
request is mapped onto the filesystem by appending their URL path to the root path. If the
filesystem path corresponds to a regular file, the service will attempt to serve it. Otherwise,
if the path corresponds to a directory containing an index.html
, the service will attempt to
serve that instead.
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
.
Fields
root: PathBuf
The root directory path to serve files from.
cache_headers: Option<u32>
Whether to send cache headers, and what lifespan to indicate.
Implementations
sourceimpl Static
impl Static
sourcepub fn new(root: impl Into<PathBuf>) -> Self
pub fn new(root: impl Into<PathBuf>) -> Self
Create a new instance of Static
with a given root path.
If Path::new("")
is given, files will be served from the current 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.
Trait Implementations
sourceimpl<B: Send + Sync + 'static> Service<Request<B>> for Static
impl<B: Send + Sync + 'static> Service<Request<B>> for Static
type Future = Pin<Box<dyn Future<Output = Result<<Static as Service<Request<B>>>::Response, <Static as Service<Request<B>>>::Error>> + Send + 'static, Global>>
type Future = Pin<Box<dyn Future<Output = Result<<Static as Service<Request<B>>>::Response, <Static as Service<Request<B>>>::Error>> + Send + 'static, Global>>
The future response value.
Auto Trait Implementations
impl RefUnwindSafe for Static
impl Send for Static
impl Sync for Static
impl Unpin for Static
impl UnwindSafe for Static
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more