pub struct Files<Err: ErrorRenderer> { /* private fields */ }Expand description
Static files handling
Files service must be registered with App::service() method.
use ntex::web::App;
use ntex_files as fs;
let app = App::new()
.service(fs::Files::new("/static", "."));Implementations§
Source§impl<Err: ErrorRenderer> Files<Err>
impl<Err: ErrorRenderer> Files<Err>
Sourcepub fn new<T: Into<PathBuf>>(path: &str, dir: T) -> Self
pub fn new<T: Into<PathBuf>>(path: &str, dir: T) -> Self
Create new Files instance for specified base directory.
File uses ThreadPool for blocking filesystem operations.
By default pool with 5x threads of available cpus is used.
Pool size can be changed by setting ACTIX_THREADPOOL environment variable.
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 redirect_to_slash_directory(self) -> Self
pub fn redirect_to_slash_directory(self) -> Self
Redirects to a slash-ended path when browsing a directory.
By default never redirect.
Sourcepub fn files_listing_renderer<F>(self, f: F) -> Self
pub fn files_listing_renderer<F>(self, f: F) -> Self
Set custom directory renderer
Sourcepub fn mime_override<F>(self, f: F) -> Self
pub fn mime_override<F>(self, f: F) -> Self
Specifies mime override callback
Sourcepub fn index_file<T: Into<String>>(self, index: T) -> Self
pub fn index_file<T: Into<String>>(self, index: T) -> Self
Set index file
Shows specific index file for directory “/” instead of showing files listing.
Sourcepub fn use_etag(self, value: bool) -> Self
pub fn use_etag(self, value: bool) -> Self
Specifies whether to use ETag or not.
Default is true.
Sourcepub fn use_last_modified(self, value: bool) -> Self
pub fn use_last_modified(self, value: bool) -> Self
Specifies whether to use Last-Modified or not.
Default is true.
Sourcepub fn use_guards<G: Guard + 'static>(self, guards: G) -> Self
pub fn use_guards<G: Guard + 'static>(self, guards: G) -> Self
Specifies custom guards to use for directory listings and files.
Default behaviour allows GET and HEAD.
Sourcepub fn disable_content_disposition(self) -> Self
pub fn disable_content_disposition(self) -> Self
Disable Content-Disposition header.
By default Content-Disposition` header is enabled.
Sourcepub fn default_handler<F, U>(self, f: F) -> Selfwhere
F: IntoServiceFactory<U, WebRequest<Err>, SharedCfg>,
U: ServiceFactory<WebRequest<Err>, SharedCfg, Response = WebResponse, Error = Err::Container> + 'static,
pub fn default_handler<F, U>(self, f: F) -> Selfwhere
F: IntoServiceFactory<U, WebRequest<Err>, SharedCfg>,
U: ServiceFactory<WebRequest<Err>, SharedCfg, Response = WebResponse, Error = Err::Container> + 'static,
Sets default handler which is used when no matched file could be found.
Trait Implementations§
Source§impl<Err: ErrorRenderer> Clone for Files<Err>
impl<Err: ErrorRenderer> Clone for Files<Err>
Source§type Response = WebResponse
type Response = WebResponse
Source§type Error = <Err as ErrorRenderer>::Container
type Error = <Err as ErrorRenderer>::Container
Source§type Service = FilesService<Err>
type Service = FilesService<Err>
Service created by this factory.Source§async fn create(&self, cfg: SharedCfg) -> Result<Self::Service, Self::InitError>
async fn create(&self, cfg: SharedCfg) -> Result<Self::Service, Self::InitError>
Source§async fn pipeline(
&self,
cfg: Cfg,
) -> Result<Pipeline<Self::Service>, Self::InitError>where
Self: Sized,
async fn pipeline(
&self,
cfg: Cfg,
) -> Result<Pipeline<Self::Service>, Self::InitError>where
Self: Sized,
Source§fn map<F, Res>(
self,
f: F,
) -> ServiceChainFactory<MapFactory<Self, F, Req, Res, Cfg>, Req, Cfg>
fn map<F, Res>( self, f: F, ) -> ServiceChainFactory<MapFactory<Self, F, Req, Res, Cfg>, Req, Cfg>
Source§fn map_err<F, E>(
self,
f: F,
) -> ServiceChainFactory<MapErrFactory<Self, Req, Cfg, F, E>, Req, Cfg>
fn map_err<F, E>( self, f: F, ) -> ServiceChainFactory<MapErrFactory<Self, Req, Cfg, F, E>, Req, Cfg>
Source§fn map_init_err<F, E>(
self,
f: F,
) -> ServiceChainFactory<MapInitErr<Self, Req, Cfg, F, E>, Req, Cfg>
fn map_init_err<F, E>( self, f: F, ) -> ServiceChainFactory<MapInitErr<Self, Req, Cfg, F, E>, Req, Cfg>
Source§impl<Err> WebServiceFactory<Err> for Files<Err>
impl<Err> WebServiceFactory<Err> for Files<Err>
fn register(self, config: &mut WebServiceConfig<Err>)
Auto Trait Implementations§
impl<Err> Freeze for Files<Err>
impl<Err> !RefUnwindSafe for Files<Err>
impl<Err> !Send for Files<Err>
impl<Err> !Sync for Files<Err>
impl<Err> Unpin for Files<Err>
impl<Err> !UnwindSafe for Files<Err>
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, Req, Cfg> IntoServiceFactory<T, Req, Cfg> for Twhere
T: ServiceFactory<Req, Cfg>,
impl<T, Req, Cfg> IntoServiceFactory<T, Req, Cfg> for Twhere
T: ServiceFactory<Req, Cfg>,
Source§fn into_factory(self) -> T
fn into_factory(self) -> T
Self to a ServiceFactory