pub struct ServeFile<FS, F = DefaultServeDirFallback> { /* private fields */ }
Expand description
Service that serves a file
Implementations§
source§impl<FS> ServeFile<FS, DefaultServeDirFallback>
impl<FS> ServeFile<FS, DefaultServeDirFallback>
sourcepub fn new<P: Into<PathBuf>>(path: P, filesystem: FS) -> Self
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.
sourcepub fn new_with_mime<P: Into<PathBuf>>(
path: P,
mime: &Mime,
filesystem: FS
) -> Self
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>
impl<FS, F> ServeFile<FS, F>
sourcepub fn with_buf_chunk_size(self, chunk_size: usize) -> Self
pub fn with_buf_chunk_size(self, chunk_size: usize) -> Self
Set a specific read buffer chunk size.
The default capacity is 64kb.
sourcepub fn precompressed_gzip(self) -> Self
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.
sourcepub fn precompressed_br(self) -> Self
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.
sourcepub fn precompressed_deflate(self) -> Self
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.