Struct static_web_server::settings::cli::General

source ·
pub struct General {
Show 40 fields pub host: String, pub port: u16, pub fd: Option<usize>, pub threads_multiplier: usize, pub max_blocking_threads: usize, pub root: PathBuf, pub page50x: PathBuf, pub page404: PathBuf, pub page_fallback: PathBuf, pub log_level: String, pub cors_allow_origins: String, pub cors_allow_headers: String, pub cors_expose_headers: String, pub http2: bool, pub http2_tls_cert: Option<PathBuf>, pub http2_tls_key: Option<PathBuf>, pub https_redirect: bool, pub https_redirect_host: String, pub https_redirect_from_port: u16, pub https_redirect_from_hosts: String, pub index_files: String, pub compression: bool, pub compression_level: CompressionLevel, pub compression_static: bool, pub directory_listing: bool, pub directory_listing_order: u8, pub directory_listing_format: DirListFmt, pub security_headers: bool, pub cache_control_headers: bool, pub basic_auth: String, pub grace_period: u8, pub config_file: PathBuf, pub log_remote_address: bool, pub redirect_trailing_slash: bool, pub ignore_hidden_files: bool, pub health: bool, pub experimental_metrics: bool, pub maintenance_mode: bool, pub maintenance_mode_status: StatusCode, pub maintenance_mode_file: PathBuf, /* private fields */
}
Expand description

General server configuration available in CLI and config file options.

Fields§

§host: String

Host address (E.g 127.0.0.1 or ::1)

§port: u16

Host port

§fd: Option<usize>

Instead of binding to a TCP port, accept incoming connections to an already-bound TCP socket listener on the specified file descriptor number (usually zero). Requires that the parent process (e.g. inetd, launchd, or systemd) binds an address and port on behalf of static-web-server, before arranging for the resulting file descriptor to be inherited by static-web-server. Cannot be used in conjunction with the port and host arguments. The included systemd unit file utilises this feature to increase security by allowing the static-web-server to be sandboxed more completely.

§threads_multiplier: usize

Number of worker threads multiplier that’ll be multiplied by the number of system CPUs using the formula: worker threads = number of CPUs * n where n is the value that changes here. When multiplier value is 0 or 1 then one thread per core is used. Number of worker threads result should be a number between 1 and 32,768 though it is advised to keep this value on the smaller side.

§max_blocking_threads: usize

Maximum number of blocking threads

§root: PathBuf

Root directory path of static files.

§page50x: PathBuf

HTML file path for 50x errors. If the path is not specified or simply doesn’t exist then the server will use a generic HTML error message. If a relative path is used then it will be resolved under the root directory.

§page404: PathBuf

HTML file path for 404 errors. If the path is not specified or simply doesn’t exist then the server will use a generic HTML error message. If a relative path is used then it will be resolved under the root directory.

§page_fallback: PathBuf
Available on crate feature fallback-page only.

HTML file path that is used for GET requests when the requested path doesn’t exist. The fallback page is served with a 200 status code, useful when using client routers. If the path is not specified or simply doesn’t exist then this feature will not be active.

§log_level: String

Specify a logging level in lower case. Values: error, warn, info, debug or trace

§cors_allow_origins: String

Specify an optional CORS list of allowed origin hosts separated by commas. Host ports or protocols aren’t being checked. Use an asterisk (*) to allow any host.

§cors_allow_headers: String

Specify an optional CORS list of allowed headers separated by commas. Default “origin, content-type”. It requires --cors-allow-origins to be used along with.

§cors_expose_headers: String

Specify an optional CORS list of exposed headers separated by commas. Default “origin, content-type”. It requires --cors-expose-origins to be used along with.

§http2: bool
Available on crate feature http2 only.

Enable HTTP/2 with TLS support.

§http2_tls_cert: Option<PathBuf>
Available on crate feature http2 only.

Specify the file path to read the certificate.

§http2_tls_key: Option<PathBuf>
Available on crate feature http2 only.

Specify the file path to read the private key.

§https_redirect: bool
Available on crate feature http2 only.

Redirect all requests with scheme “http” to “https” for the current server instance. It depends on “http2” to be enabled.

§https_redirect_host: String
Available on crate feature http2 only.

Canonical host name or IP of the HTTPS (HTTPS/2) server. It depends on “https_redirect” to be enabled.

§https_redirect_from_port: u16
Available on crate feature http2 only.

HTTP host port where the redirect server will listen for requests to redirect them to HTTPS. It depends on “https_redirect” to be enabled.

§https_redirect_from_hosts: String
Available on crate feature http2 only.

List of host names or IPs allowed to redirect from. HTTP requests must contain the HTTP ‘Host’ header and match against this list. It depends on “https_redirect” to be enabled.

§index_files: String

List of files that will be used as an index for requests ending with the slash character (‘/’). Files are checked in the specified order.

§compression: bool
Available on crate features compression or compression-gzip or compression-brotli or compression-zstd or compression-deflate only.

Gzip, Deflate, Brotli or Zstd compression on demand determined by the Accept-Encoding header and applied to text-based web file types only.

§compression_level: CompressionLevel
Available on crate features compression or compression-gzip or compression-brotli or compression-zstd or compression-deflate only.

Compression level to apply for Gzip, Deflate, Brotli or Zstd compression.

§compression_static: bool
Available on crate features compression or compression-gzip or compression-brotli or compression-zstd or compression-deflate only.

Look up the pre-compressed file variant (.gz, .br or .zst) on disk of a requested file and serves it directly if available. The compression type is determined by the Accept-Encoding header.

§directory_listing: bool
Available on crate feature directory-listing only.

Enable directory listing for all requests ending with the slash character (‘/’).

§directory_listing_order: u8
Available on crate feature directory-listing only.

Specify a default code number to order directory listing entries per Name, Last modified or Size attributes (columns). Code numbers supported: 0 (Name asc), 1 (Name desc), 2 (Last modified asc), 3 (Last modified desc), 4 (Size asc), 5 (Size desc). Default 6 (unordered)

§directory_listing_format: DirListFmt
Available on crate feature directory-listing only.

Specify a content format for directory listing entries. Formats supported: “html” or “json”. Default “html”.

§security_headers: bool

Enable security headers by default when HTTP/2 feature is activated. Headers included: “Strict-Transport-Security: max-age=63072000; includeSubDomains; preload” (2 years max-age), “X-Frame-Options: DENY” and “Content-Security-Policy: frame-ancestors ‘self’”.

§cache_control_headers: bool

Enable cache control headers for incoming requests based on a set of file types. The file type list can be found on src/control_headers.rs file.

§basic_auth: String
Available on crate feature basic-auth only.

It provides The “Basic” HTTP Authentication scheme using credentials as “user-id:password” pairs. Password must be encoded using the “BCrypt” password-hashing function.

§grace_period: u8

Defines a grace period in seconds after a SIGTERM signal is caught which will delay the server before to shut it down gracefully. The maximum value is 255 seconds.

§config_file: PathBuf

Server TOML configuration file path.

§log_remote_address: bool

Log incoming requests information along with its remote address if available using the info log level.

§redirect_trailing_slash: bool

Check for a trailing slash in the requested directory URI and redirect permanently (308) to the same path with a trailing slash suffix if it is missing.

§ignore_hidden_files: bool

Ignore hidden files/directories (dotfiles), preventing them to be served and being included in auto HTML index pages (directory listing).

§health: bool

Add a /health endpoint that doesn’t generate any log entry and returns a 200 status code. This is especially useful with Kubernetes liveness and readiness probes.

§experimental_metrics: bool
Available on Unix and crate feature experimental only.

Add a /metrics endpoint that returns a Prometheus metrics response.

§maintenance_mode: bool

Enable the server’s maintenance mode functionality.

§maintenance_mode_status: StatusCode

Provide a custom HTTP status code when entering into maintenance mode. Default 503.

§maintenance_mode_file: PathBuf

Provide a custom maintenance mode HTML file. If not provided then a generic message will be displayed.

Trait Implementations§

source§

impl Args for General

source§

fn group_id() -> Option<Id>

Report the ArgGroup::id for this set of arguments
source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate Self. Read more
source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to Command so it can update self. Read more
source§

impl CommandFactory for General

source§

fn command<'b>() -> Command

Build a Command that can instantiate Self. Read more
source§

fn command_for_update<'b>() -> Command

Build a Command that can update self. Read more
source§

impl Debug for General

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromArgMatches for General

source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches ) -> Result<(), Error>

Assign values from ArgMatches to self.
source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches ) -> Result<(), Error>

Assign values from ArgMatches to self.
source§

impl Parser for General

source§

fn parse() -> Self

Parse from std::env::args_os(), exit on error.
source§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
source§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, exit on error.
source§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
source§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, exit on error.
source§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.

Auto Trait Implementations§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more