Files

Struct Files 

Source
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>

Source

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.

Source

pub fn show_files_listing(self) -> Self

Show files listing for directories.

By default show files listing is disabled.

Source

pub fn redirect_to_slash_directory(self) -> Self

Redirects to a slash-ended path when browsing a directory.

By default never redirect.

Source

pub fn files_listing_renderer<F>(self, f: F) -> Self
where for<'r, 's> F: Fn(&'r Directory, &'s HttpRequest) -> Result<WebResponse, Error> + 'static,

Set custom directory renderer

Source

pub fn mime_override<F>(self, f: F) -> Self
where F: Fn(&Name<'_>) -> DispositionType + 'static,

Specifies mime override callback

Source

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.

Source

pub fn use_etag(self, value: bool) -> Self

Specifies whether to use ETag or not.

Default is true.

Source

pub fn use_last_modified(self, value: bool) -> Self

Specifies whether to use Last-Modified or not.

Default is true.

Source

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.

Source

pub fn disable_content_disposition(self) -> Self

Disable Content-Disposition header.

By default Content-Disposition` header is enabled.

Source

pub fn default_handler<F, U>(self, f: F) -> Self
where 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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Err> ServiceFactory<WebRequest<Err>, SharedCfg> for Files<Err>
where Err: ErrorRenderer, Err::Container: From<FilesError>,

Source§

type Response = WebResponse

Responses given by the created services.
Source§

type Error = <Err as ErrorRenderer>::Container

Errors produced by the created services.
Source§

type Service = FilesService<Err>

The kind of Service created by this factory.
Source§

type InitError = ()

Errors potentially raised while building a service.
Source§

async fn create(&self, cfg: SharedCfg) -> Result<Self::Service, Self::InitError>

Create and return a new service value asynchronously.
Source§

async fn pipeline( &self, cfg: Cfg, ) -> Result<Pipeline<Self::Service>, Self::InitError>
where Self: Sized,

Create and return a new service value asynchronously and wrap into a container
Source§

fn map<F, Res>( self, f: F, ) -> ServiceChainFactory<MapFactory<Self, F, Req, Res, Cfg>, Req, Cfg>
where Self: Sized, F: Fn(Self::Response) -> Res + Clone,

Map this service’s output to a different type, returning a new service of the resulting type.
Source§

fn map_err<F, E>( self, f: F, ) -> ServiceChainFactory<MapErrFactory<Self, Req, Cfg, F, E>, Req, Cfg>
where Self: Sized, F: Fn(Self::Error) -> E + Clone,

Map this service’s error to a different error, returning a new service.
Source§

fn map_init_err<F, E>( self, f: F, ) -> ServiceChainFactory<MapInitErr<Self, Req, Cfg, F, E>, Req, Cfg>
where Self: Sized, F: Fn(Self::InitError) -> E + Clone,

Map this factory’s init error to a different error, returning a new service.
Source§

impl<Err> WebServiceFactory<Err> for Files<Err>
where Err: ErrorRenderer, Err::Container: From<FilesError>,

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, Req, Cfg> IntoServiceFactory<T, Req, Cfg> for T
where T: ServiceFactory<Req, Cfg>,

Source§

fn into_factory(self) -> T

Convert Self to a ServiceFactory
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.