Struct gotham::handler::FileOptions
source · [−]pub struct FileOptions { /* private fields */ }
Expand description
Options to pass to file or dir handlers. Allows overriding default behaviour for compression, cache control headers, etc.
FileOptions
implements From
for String
and PathBuf
(and related reference types) - so that a
path can be passed to router builder methods if only default options are required.
For overridding default options, FileOptions
provides builder methods. The default
values and use of the builder methods are shown in the example below.
let default_options = FileOptions::from("my_static_path");
let from_builder = FileOptions::new("my_static_path")
.with_cache_control("public")
.with_gzip(false)
.with_brotli(false)
.build();
assert_eq!(default_options, from_builder);
Implementations
sourceimpl FileOptions
impl FileOptions
sourcepub fn new<P: AsRef<Path>>(path: P) -> Selfwhere
PathBuf: From<P>,
pub fn new<P: AsRef<Path>>(path: P) -> Selfwhere
PathBuf: From<P>,
Create a new FileOptions
with default values.
sourcepub fn with_cache_control(&mut self, cache_control: &str) -> &mut Self
pub fn with_cache_control(&mut self, cache_control: &str) -> &mut Self
Sets the “cache_control” header in static file responses to the given value.
sourcepub fn with_gzip(&mut self, gzip: bool) -> &mut Self
pub fn with_gzip(&mut self, gzip: bool) -> &mut Self
If true
, given a request for FILE, serves FILE.gz if it exists in the static directory and
if the accept-encoding header is set to allow gzipped content (defaults to false).
sourcepub fn with_brotli(&mut self, brotli: bool) -> &mut Self
pub fn with_brotli(&mut self, brotli: bool) -> &mut Self
If true
, given a request for FILE, serves FILE.br if it exists in the static directory and
if the accept-encoding header is set to allow brotli content (defaults to false).
Trait Implementations
sourceimpl Clone for FileOptions
impl Clone for FileOptions
sourcefn clone(&self) -> FileOptions
fn clone(&self) -> FileOptions
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more