Struct tower_http::services::ServeFile
source · pub struct ServeFile(_);
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 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§
source§impl<ReqBody> Service<Request<ReqBody>> for ServeFilewhere
ReqBody: Send + 'static,
impl<ReqBody> Service<Request<ReqBody>> for ServeFilewhere ReqBody: Send + 'static,
§type Error = <ServeDir<DefaultServeDirFallback> as Service<Request<ReqBody>>>::Error
type Error = <ServeDir<DefaultServeDirFallback> as Service<Request<ReqBody>>>::Error
§type Response = <ServeDir<DefaultServeDirFallback> as Service<Request<ReqBody>>>::Response
type Response = <ServeDir<DefaultServeDirFallback> as Service<Request<ReqBody>>>::Response
§type Future = <ServeDir<DefaultServeDirFallback> as Service<Request<ReqBody>>>::Future
type Future = <ServeDir<DefaultServeDirFallback> as Service<Request<ReqBody>>>::Future
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 Twhere
T: Service<Request> + ?Sized,
impl<T, Request> ServiceExt<Request> for Twhere T: Service<Request> + ?Sized,
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 call_all<S>(self, reqs: S) -> CallAll<Self, S>where
Self: Sized,
Self::Error: Into<Box<dyn Error + Send + Sync, Global>>,
S: Stream<Item = Request>,
fn call_all<S>(self, reqs: S) -> CallAll<Self, S>where Self: Sized, Self::Error: Into<Box<dyn Error + Send + Sync, Global>>, S: Stream<Item = Request>,
source§fn and_then<F>(self, f: F) -> AndThen<Self, F>where
Self: Sized,
F: Clone,
fn and_then<F>(self, f: F) -> AndThen<Self, F>where Self: Sized, F: Clone,
poll_ready
method. Read moresource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>where
Self: Sized,
F: FnOnce(Self::Response) -> Response + Clone,
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>where Self: Sized, F: FnOnce(Self::Response) -> Response + Clone,
poll_ready
method. Read moresource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>where
Self: Sized,
F: FnOnce(Self::Error) -> Error + Clone,
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>where Self: Sized, F: FnOnce(Self::Error) -> Error + Clone,
poll_ready
method. Read moresource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>where
Self: Sized,
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Result<Response, Error> + Clone,
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>where Self: Sized, Error: From<Self::Error>, F: FnOnce(Result<Self::Response, Self::Error>) -> Result<Response, Error> + Clone,
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read more