Struct tower_http::services::ServeFile
source · 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 precompressed_zstd(self) -> Self
pub fn precompressed_zstd(self) -> Self
Informs the service that it should also look for a precompressed zstd version of the file.
If the client has an Accept-Encoding
header that allows the zstd encoding,
the file foo.txt.zst
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 fn try_call<ReqBody>(
&mut self,
req: Request<ReqBody>
) -> ResponseFuture<ReqBody> ⓘwhere
ReqBody: Send + 'static,
pub fn try_call<ReqBody>(
&mut self,
req: Request<ReqBody>
) -> ResponseFuture<ReqBody> ⓘ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 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> 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 ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
source§fn ready_and(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready_and(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
ServiceExt::ready
method insteadsource§fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
source§fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
Service
, calling with the providing request once it is ready.source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready
method. Read moresource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready
method. Read moresource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready
method. Read moresource§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