pub struct ServeFile(/* private fields */);
fs
only.Expand description
Service that serves a file.
Implementations§
Source§impl ServeFile
impl ServeFile
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Self
pub fn new<P: AsRef<Path>>(path: P) -> Self
Create a new ServeFile
.
The Content-Type
will be guessed from the file extension.
Sourcepub fn new_with_mime<P: AsRef<Path>>(path: P, mime: &Mime) -> Self
pub fn new_with_mime<P: AsRef<Path>>(path: P, mime: &Mime) -> Self
Create a new ServeFile
with a specific mime type.
§Panics
Will panic if the mime type isn’t a valid header value.
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 the file.
If the client has an Accept-Encoding
header that allows the gzip encoding,
the file foo.txt.gz
will be served instead of 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 same 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 the file.
If the client has an Accept-Encoding
header that allows the brotli encoding,
the file foo.txt.br
will be served instead of 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 same 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 the file.
If the client has an Accept-Encoding
header that allows the deflate encoding,
the file foo.txt.zz
will be served instead of 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 same directory. Different precompressed
variants can be combined.
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 async fn try_call<ReqBody>(
&self,
req: Request<ReqBody>,
) -> Result<Response<ResponseBody>, Error>where
ReqBody: Send + 'static,
pub async fn try_call<ReqBody>(
&self,
req: Request<ReqBody>,
) -> Result<Response<ResponseBody>, Error>where
ReqBody: Send + 'static,
Call the service and get a future that contains any std::io::Error
that might have
happened.
See ServeDir::try_call
for more details.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ServeFile
impl !RefUnwindSafe for ServeFile
impl Send for ServeFile
impl Sync for ServeFile
impl Unpin for ServeFile
impl !UnwindSafe for ServeFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn oneshot(
self,
req: Request,
) -> impl Future<Output = Result<Self::Response, Self::Error>>where
Self: Sized,
fn oneshot(
self,
req: Request,
) -> impl Future<Output = Result<Self::Response, Self::Error>>where
Self: Sized,
Service
, calling it with the provided request once and only once.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
Source§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
Source§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
Source§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read more