Struct http_dir::ServeFile

source ·
pub struct ServeFile<FS, F = DefaultServeDirFallback> { /* private fields */ }
Expand description

Service that serves a file

Implementations§

source§

impl<FS> ServeFile<FS, DefaultServeDirFallback>

source

pub fn new<P: Into<PathBuf>>(path: P, filesystem: FS) -> Self

Create a new ServeFile.

The Content-Type will be guessed from the file extension.

source

pub fn new_with_mime<P: Into<PathBuf>>( path: P, mime: &Mime, filesystem: FS ) -> Self

Create a new ServeFile with a specific mime type.

Panics

Will panic if the mime type isn’t a valid header value.

source§

impl<FS, F> ServeFile<FS, F>

source

pub fn with_buf_chunk_size(self, chunk_size: usize) -> Self

Set a specific read buffer chunk size.

The default capacity is 64kb.

source

pub fn precompressed_gzip(self) -> Self

Informs the service that it should also look for a precompressed gzip version of any file in the directory.

Assuming the dir directory is being served and dir/foo.txt is requested, a client with an Accept-Encoding header that allows the gzip encoding will receive the file dir/foo.txt.gz instead of dir/foo.txt. If the precompressed file is not available, or the client doesn’t support it, the uncompressed version will be served instead. Both the precompressed version and the uncompressed version are expected to be present in the directory. Different precompressed variants can be combined.

source

pub fn precompressed_br(self) -> Self

Informs the service that it should also look for a precompressed brotli version of any file in the directory.

Assuming the dir directory is being served and dir/foo.txt is requested, a client with an Accept-Encoding header that allows the brotli encoding will receive the file dir/foo.txt.br instead of dir/foo.txt. If the precompressed file is not available, or the client doesn’t support it, the uncompressed version will be served instead. Both the precompressed version and the uncompressed version are expected to be present in the directory. Different precompressed variants can be combined.

source

pub fn precompressed_deflate(self) -> Self

Informs the service that it should also look for a precompressed deflate version of any file in the directory.

Assuming the dir directory is being served and dir/foo.txt is requested, a client with an Accept-Encoding header that allows the deflate encoding will receive the file dir/foo.txt.zz instead of dir/foo.txt. If the precompressed file is not available, or the client doesn’t support it, the uncompressed version will be served instead. Both the precompressed version and the uncompressed version are expected to be present in the directory. Different precompressed variants can be combined.

Trait Implementations§

source§

impl<FS: Clone, F: Clone> Clone for ServeFile<FS, F>

source§

fn clone(&self) -> ServeFile<FS, F>

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<FS: Debug, F: Debug> Debug for ServeFile<FS, F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<ReqBody, F, FResBody, FS> Service<Request<ReqBody>> for ServeFile<FS, F>where F: Service<Request<ReqBody>, Response = Response<FResBody>> + Clone, F::Error: Into<Error>, F::Future: Send, FResBody: Body<Data = Bytes> + Send + 'static, FResBody::Error: Into<Box<dyn Error + Send + Sync>>, FS: Filesystem + Clone + Send + Sync + 'static, FS::File: 'static,

§

type Response = Response<UnsyncBoxBody<Bytes, Error>>

Responses given by the service.
§

type Error = Error

Errors produced by the service.
§

type Future = impl Future<Output = Result<<ServeFile<FS, F> as Service<Request<ReqBody>>>::Response, <ServeFile<FS, F> as Service<Request<ReqBody>>>::Error>>

The future response value.
source§

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
source§

fn call(&mut self, req: Request<ReqBody>) -> Self::Future

Process the request and return the response asynchronously. Read more

Auto Trait Implementations§

§

impl<FS, F> RefUnwindSafe for ServeFile<FS, F>where F: RefUnwindSafe, FS: RefUnwindSafe,

§

impl<FS, F> Send for ServeFile<FS, F>where F: Send, FS: Send,

§

impl<FS, F> Sync for ServeFile<FS, F>where F: Sync, FS: Sync,

§

impl<FS, F> Unpin for ServeFile<FS, F>where F: Unpin, FS: Unpin,

§

impl<FS, F> UnwindSafe for ServeFile<FS, F>where F: UnwindSafe, FS: UnwindSafe,

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