Struct actix_web::fs::StaticFiles
source · pub struct StaticFiles<S, C = DefaultConfig> { /* private fields */ }
Expand description
Static files handling
StaticFile
handler must be registered with App::handler()
method,
because StaticFile
handler requires access sub-path information.
use actix_web::{fs, App};
fn main() {
let app = App::new()
.handler("/static", fs::StaticFiles::new(".").unwrap())
.finish();
}
Implementations
sourceimpl<S: 'static> StaticFiles<S>
impl<S: 'static> StaticFiles<S>
sourcepub fn new<T: Into<PathBuf>>(dir: T) -> Result<StaticFiles<S>, Error>
pub fn new<T: Into<PathBuf>>(dir: T) -> Result<StaticFiles<S>, Error>
Create new StaticFiles
instance for specified base directory.
StaticFile
uses CpuPool
for blocking filesystem operations.
By default pool with 20 threads is used.
Pool size can be changed by setting ACTIX_CPU_POOL environment variable.
sourceimpl<S: 'static, C: StaticFileConfig> StaticFiles<S, C>
impl<S: 'static, C: StaticFileConfig> StaticFiles<S, C>
sourcepub fn with_config<T: Into<PathBuf>>(
dir: T,
config: C
) -> Result<StaticFiles<S, C>, Error>
pub fn with_config<T: Into<PathBuf>>(
dir: T,
config: C
) -> Result<StaticFiles<S, C>, Error>
Create new StaticFiles
instance for specified base directory.
Identical with new
but allows to specify configiration to use.
sourcepub fn with_config_pool<T: Into<PathBuf>>(
dir: T,
pool: CpuPool,
_: C
) -> Result<StaticFiles<S, C>, Error>
pub fn with_config_pool<T: Into<PathBuf>>(
dir: T,
pool: CpuPool,
_: C
) -> Result<StaticFiles<S, C>, Error>
Create new StaticFiles
instance for specified base directory with config and
CpuPool
.
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 files_listing_renderer<F>(self, f: F) -> Selfwhere
for<'r, 's> F: Fn(&'r Directory, &'s HttpRequest<S>) -> Result<HttpResponse, Error> + 'static,
pub fn files_listing_renderer<F>(self, f: F) -> Selfwhere
for<'r, 's> F: Fn(&'r Directory, &'s HttpRequest<S>) -> Result<HttpResponse, Error> + 'static,
Set custom directory renderer
sourcepub fn index_file<T: Into<String>>(self, index: T) -> StaticFiles<S, C>
pub fn index_file<T: Into<String>>(self, index: T) -> StaticFiles<S, C>
Set index file
Redirects to specific index file for directory “/” instead of showing files listing.
sourcepub fn default_handler<H: Handler<S>>(self, handler: H) -> StaticFiles<S, C>
pub fn default_handler<H: Handler<S>>(self, handler: H) -> StaticFiles<S, C>
Sets default handler which is used when no matched file could be found.