Struct poem::endpoint::StaticFilesEndpoint
source · pub struct StaticFilesEndpoint { /* private fields */ }
Expand description
Implementations§
source§impl StaticFilesEndpoint
impl StaticFilesEndpoint
sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
Create new static files service for a specified base directory.
§Example
use poem::{endpoint::StaticFilesEndpoint, Route};
let app = Route::new().nest(
"/files",
StaticFilesEndpoint::new("/etc/www")
.show_files_listing()
.index_file("index.html"),
);
sourcepub fn show_files_listing(self) -> Self
pub fn show_files_listing(self) -> Self
Show files listing for directories.
By default show files listing is disabled.
sourcepub fn index_file(self, index: impl Into<String>) -> Self
pub fn index_file(self, index: impl Into<String>) -> Self
Set index file
Shows specific index file for directories instead of showing files listing.
If the index file is not found, files listing is shown as a fallback if Files::show_files_listing() is set.
sourcepub fn prefer_utf8(self, value: bool) -> Self
pub fn prefer_utf8(self, value: bool) -> Self
Specifies whether text responses should signal a UTF-8 encoding.
Default is true
.
sourcepub fn redirect_to_slash_directory(self) -> Self
pub fn redirect_to_slash_directory(self) -> Self
Redirects to a slash-ended path when browsing a directory.
sourcepub fn fallback_to_index(self) -> Self
pub fn fallback_to_index(self) -> Self
Fall back to the configured index file if any, if the file is not found
Trait Implementations§
source§impl Endpoint for StaticFilesEndpoint
impl Endpoint for StaticFilesEndpoint
Auto Trait Implementations§
impl Freeze for StaticFilesEndpoint
impl RefUnwindSafe for StaticFilesEndpoint
impl Send for StaticFilesEndpoint
impl Sync for StaticFilesEndpoint
impl Unpin for StaticFilesEndpoint
impl UnwindSafe for StaticFilesEndpoint
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
source§impl<T> EndpointExt for Twhere
T: IntoEndpoint,
impl<T> EndpointExt for Twhere
T: IntoEndpoint,
source§fn boxed<'a>(self) -> BoxEndpoint<'a, <Self::Endpoint as Endpoint>::Output>where
Self: Sized + 'a,
fn boxed<'a>(self) -> BoxEndpoint<'a, <Self::Endpoint as Endpoint>::Output>where
Self: Sized + 'a,
Wrap the endpoint in a Box.
source§fn with<T>(self, middleware: T) -> T::Output
fn with<T>(self, middleware: T) -> T::Output
Use middleware to transform this endpoint. Read more
source§fn data<T>(self, data: T) -> AddDataEndpoint<Self::Endpoint, T>
fn data<T>(self, data: T) -> AddDataEndpoint<Self::Endpoint, T>
Attach a state data to the endpoint, similar to
with(AddData(T))
. Read moresource§fn data_opt<T>(
self,
data: Option<T>
) -> EitherEndpoint<AddDataEndpoint<Self::Endpoint, T>, Self>
fn data_opt<T>( self, data: Option<T> ) -> EitherEndpoint<AddDataEndpoint<Self::Endpoint, T>, Self>
if
data
is Some(T)
then attach the value to the endpoint.source§fn after<F, Fut, T>(self, f: F) -> After<Self::Endpoint, F>
fn after<F, Fut, T>(self, f: F) -> After<Self::Endpoint, F>
Maps the output of this endpoint. Read more
source§fn around<F, Fut, R>(self, f: F) -> Around<Self::Endpoint, F>
fn around<F, Fut, R>(self, f: F) -> Around<Self::Endpoint, F>
Maps the request and response of this endpoint. Read more
source§fn map_to_response(self) -> MapToResponse<Self::Endpoint>where
Self: Sized,
fn map_to_response(self) -> MapToResponse<Self::Endpoint>where
Self: Sized,
source§fn to_response(self) -> ToResponse<Self::Endpoint>where
Self: Sized,
fn to_response(self) -> ToResponse<Self::Endpoint>where
Self: Sized,
source§fn map<F, Fut, R, R2>(self, f: F) -> Map<Self::Endpoint, F>
fn map<F, Fut, R, R2>(self, f: F) -> Map<Self::Endpoint, F>
Maps the response of this endpoint. Read more
source§fn catch_all_error<F, Fut, R>(self, f: F) -> CatchAllError<Self, F, R>
fn catch_all_error<F, Fut, R>(self, f: F) -> CatchAllError<Self, F, R>
Catch all errors and convert it into a response. Read more
source§fn catch_error<F, Fut, R, ErrType>(
self,
f: F
) -> CatchError<Self, F, R, ErrType>
fn catch_error<F, Fut, R, ErrType>( self, f: F ) -> CatchError<Self, F, R, ErrType>
Catch the specified type of error and convert it into a response. Read more
source§fn inspect_all_err<F>(self, f: F) -> InspectAllError<Self, F>
fn inspect_all_err<F>(self, f: F) -> InspectAllError<Self, F>
Does something with each error. Read more
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoEndpoint for Twhere
T: Endpoint,
impl<T> IntoEndpoint for Twhere
T: Endpoint,
source§fn into_endpoint(self) -> <T as IntoEndpoint>::Endpoint
fn into_endpoint(self) -> <T as IntoEndpoint>::Endpoint
Converts this object into endpoint.
source§impl<T> TowerCompatExt for T
impl<T> TowerCompatExt for T
source§fn compat<ResBody, Err, Fut>(self) -> TowerCompatEndpoint<Self>where
ResBody: Body + Send + Sync + 'static,
ResBody::Data: Into<Bytes> + Send + 'static,
ResBody::Error: StdError + Send + Sync + 'static,
Err: Into<Error>,
Self: Service<Request<BoxBody<Bytes, Error>>, Response = Response<ResBody>, Error = Err, Future = Fut> + Clone + Send + Sync + Sized + 'static,
Fut: Future<Output = Result<Response<ResBody>, Err>> + Send + 'static,
fn compat<ResBody, Err, Fut>(self) -> TowerCompatEndpoint<Self>where
ResBody: Body + Send + Sync + 'static,
ResBody::Data: Into<Bytes> + Send + 'static,
ResBody::Error: StdError + Send + Sync + 'static,
Err: Into<Error>,
Self: Service<Request<BoxBody<Bytes, Error>>, Response = Response<ResBody>, Error = Err, Future = Fut> + Clone + Send + Sync + Sized + 'static,
Fut: Future<Output = Result<Response<ResBody>, Err>> + Send + 'static,
Available on crate feature
tower-compat
only.Converts a tower service to a poem endpoint.