Skip to main content

General

Struct General 

Source
pub struct General {
Show 57 fields pub host: String, pub port: u16, pub fd: Option<usize>, pub unix_socket: Option<PathBuf>, pub unix_socket_mode: Option<u32>, pub unix_socket_force: bool, pub threads_multiplier: usize, pub max_blocking_threads: usize, pub root: PathBuf, pub use_relative_root: bool, pub page50x: PathBuf, pub page404: PathBuf, pub page_fallback: PathBuf, pub log_level: String, pub log_format: LogFormat, pub log_with_ansi: bool, pub log_file: Option<PathBuf>, pub cors_allow_origins: String, pub cors_allow_headers: String, pub cors_expose_headers: String, pub tls: bool, pub tls_cert: Option<PathBuf>, pub tls_key: Option<PathBuf>, pub http2: bool, 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 directory_listing_download: Vec<DirDownloadFmt>, pub security_headers: bool, pub cache_control_headers: bool, pub etag: bool, pub basic_auth: String, pub grace_period: u8, pub config_file: PathBuf, pub log_remote_address: bool, pub log_x_real_ip: bool, pub log_forwarded_for: bool, pub trusted_proxies: Vec<IpAddr>, pub redirect_trailing_slash: bool, pub include_hidden: bool, pub follow_symlinks: bool, pub accept_markdown: bool, pub text_charset: bool, pub health: bool, pub metrics: bool, pub maintenance_mode: bool, pub maintenance_mode_status: StatusCode, pub maintenance_mode_file: PathBuf, pub commands: Option<Commands>, /* 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.

§unix_socket: Option<PathBuf>
Available on Unix only.

Bind the server to a Unix Domain Socket (UDS) at the given filesystem path instead of a TCP host/port. Useful for reverse-proxy setups (e.g. nginx) on the same host where TCP/IP overhead is undesirable and filesystem-based access control is preferred. Cannot be combined with --host, --port, --fd, or TLS-related options. The socket file is removed on a graceful shutdown.

§unix_socket_mode: Option<u32>
Available on Unix only.

Filesystem permission bits applied to the Unix socket file after binding, expressed in octal (e.g. 660, 0660, or 0o660). When omitted the socket is created with the process umask. Only meaningful together with --unix-socket.

§unix_socket_force: bool
Available on Unix only.

When true, remove an existing socket file at --unix-socket before binding. This is useful when the server was previously killed abruptly and left a stale socket behind. Defaults to false to avoid clobbering an unrelated file.

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

§use_relative_root: bool

Resolve the web root directory at request time rather than at startup, allowing symlinked root directories to be swapped at runtime.

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

A HTML file path (not relative to the root) 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 doesn’t exist then the feature is not activated.

§log_level: String

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

§log_format: LogFormat

Specify the logging output format. Values: json (structured single-line JSON for production) or pretty (human-readable text for development)

§log_with_ansi: bool

Enable or disable ANSI escape codes for colors and other text formatting of the log output. Only effective when --log-format pretty is used.

§log_file: Option<PathBuf>

Optional filesystem path to stream log records to in addition to stderr. When set, logs are written asynchronously through a background worker thread (non-blocking I/O), so the request path is never delayed by disk writes. Missing parent directories are created on startup. ANSI escape codes are always disabled for file output regardless of --log-with-ansi. The file uses the format selected by --log-format (JSON by default). The file is opened in append mode and is not rotated by SWS, use an external tool (e.g. logrotate) for rotation.

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

§tls: bool
Available on crate feature tls only.

Enable TLS/HTTPS support. Requires –tls-cert and –tls-key.

§tls_cert: Option<PathBuf>
Available on crate feature tls only.

Specify the file path to the TLS certificate.

§tls_key: Option<PathBuf>
Available on crate feature tls only.

Specify the file path to the TLS private key.

§http2: bool
Available on crate feature http2 only.

Enable HTTP/2 protocol support. Requires TLS to be enabled (–tls).

§https_redirect: bool
Available on crate feature tls only.

Redirect all requests with scheme “http” to “https” for the current server instance. Requires TLS to be enabled (–tls).

§https_redirect_host: String
Available on crate feature tls only.

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

§https_redirect_from_port: u16
Available on crate feature tls 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 tls 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-brotli or compression-deflate or compression-gzip or compression-zstd or compression 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-brotli or compression-deflate or compression-gzip or compression-zstd or compression only.

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

§compression_static: bool

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”.

§directory_listing_download: Vec<DirDownloadFmt>
Available on crate feature directory-listing-download only.

Specify list of enabled format(s) for directory download. Format supported: targz. Default to empty list (disabled).

§security_headers: bool

Enable security headers by default when TLS 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.

§etag: bool

Enable weak ETag headers (W/"<mtime>-<size>") and full conditional request handling (If-None-Match, If-Match, If-Range). Composes with --cache-control-headers; emits validators on every static-file response so clients can revalidate hot HTML even when long max-age is configured elsewhere.

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

§log_x_real_ip: bool

Log the X-Real-IP header for remote IP information.

§log_forwarded_for: bool

Log the X-Forwarded-For header for remote IP information

§trusted_proxies: Vec<IpAddr>

List of IPs to use X-Forwarded-For from. The default is to trust all

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

§include_hidden: bool

Include hidden files/directories (dotfiles), allowing them to be served and listed in auto HTML index pages (directory listing). Disabled by default; hidden files return 404 Not Found.

§follow_symlinks: bool

Follow symbolic links when serving files or directories. Disabled by default; requests whose path contains any symlink component return 403 Forbidden.

§accept_markdown: bool

Enable markdown content negotiation. When a client sends Accept: text/markdown, serve .md or .html.md files if available.

§text_charset: bool

Set a default charset=utf-8 parameter on limited set of text responses that don’t already have one.

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

§metrics: bool
Available on crate feature metrics only.

Enable the /metrics endpoint that exposes Prometheus metrics for HTTP requests, connections, and latency.

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

§commands: Option<Commands>

Subcommands for additional maintenance tasks, like installing and uninstalling the SWS Windows Service and generation of completions and man pages

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 via FromArgMatches::from_arg_matches_mut Read more
Source§

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

Append to Command so it can instantiate self via FromArgMatches::update_from_arg_matches_mut 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. Read more
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

Source§

type Output = T

Should always be Self
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.
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