Skip to main content

HttpOptions

Struct HttpOptions 

Source
pub struct HttpOptions {
Show 19 fields pub addr: String, pub api_prefix: String, pub cors: CorsOptions, pub timeout_secs: u64, pub body_limit_bytes: usize, pub per_ip_rate_limit: Option<u32>, pub rate_limit_store: Option<String>, pub rate_limit_ipv6_prefix: u8, pub security_headers: bool, pub compression: bool, pub maintenance_file: PathBuf, pub maintenance_except: Vec<String>, pub trust_proxy: bool, pub trusted_proxies: Vec<String>, pub signing_key: Option<Secret<String>>, pub shutdown_grace_secs: u64, pub errors: ErrorOptions, pub server: ServerOptions, pub multipart: MultipartLimits,
}
Expand description

HTTP server settings (configuration section http; every key optional).

[http]
addr = "0.0.0.0:8080"
api_prefix = "/api"
timeout_secs = 30
cors = { allowed_origins = ["http://localhost:3000"] }
errors = { code = true }
server = { max_connections = 10000 }

Fields§

§addr: String

The address serve binds (default 127.0.0.1:8080).

§api_prefix: String

The prefix of every controller route (default /api); routes whose path starts with ! ignore it.

§cors: CorsOptions

Cross-origin settings.

§timeout_secs: u64

The request timeout (default 30 s); routes may override it.

§body_limit_bytes: usize

The default request body limit (default 2 MiB); routes may override it.

§per_ip_rate_limit: Option<u32>

Requests per minute per client IP (default Some(600); None disables). Counted in each process, and also in the store http.rate_limit_store names when every process shares one ("redis" with RedisModule).

§rate_limit_store: Option<String>

Where the per-IP limit and route throttles also count: unset or "memory", only in each process; else in the dyn RateLimitStore registered under this name ("redis" with RedisModule) too, so every process counts them together. A name nothing registered stops the boot.

§rate_limit_ipv6_prefix: u8

How much of an IPv6 address names a client for every per-IP limit (this one, route throttles for guests, the sign-in throttles, the OAuth endpoint limits): the first rate_limit_ipv6_prefix bits, so all addresses of one network share one budget (default 64: one /64, the smallest allocation a provider normally gives a customer; 1 to 128). IPv4 clients are counted per address, and IPv4-mapped IPv6 addresses (::ffff:192.0.2.1) as IPv4. See rate_limit_key.

§security_headers: bool

Send the default security headers (default true).

§compression: bool

Compress responses (default true): with gzip, and the pages and ops of navree-ui with brotli. Off, no response is compressed by either. A route opts out with no_compression and a response with Cache-Control: no-transform, from both: see the BREACH note on CompressionLayer.

§maintenance_file: PathBuf

While this file exists the app answers 503 (default storage/framework/down).

§maintenance_except: Vec<String>

Request paths still served during maintenance, matched exactly (default /health/live, /health/ready and /metrics, so probes and scrapes keep working and an orchestrator does not restart instances that are only down for maintenance). From the environment, a comma-separated list (APP_HTTP__MAINTENANCE_EXCEPT=/health/live,/up).

§trust_proxy: bool

Take the client IP from X-Forwarded-For / X-Real-IP sent by any peer (default false; enable only when every request comes through a reverse proxy that sets them). Prefer trusted_proxies.

§trusted_proxies: Vec<String>

The reverse proxies (and backends-for-frontends) whose X-Forwarded-For / X-Real-IP name the client: IP addresses or CIDR blocks (127.0.0.1, ::1, 10.0.0.0/8). A request from any other peer is identified by its own address, so clients reaching the app directly cannot choose theirs. In X-Forwarded-For, the client is the first address from the right that is not a listed proxy. When set, it replaces trust_proxy. From the environment, a comma-separated list (APP_HTTP__TRUSTED_PROXIES=127.0.0.1,::1).

§signing_key: Option<Secret<String>>

The key for signed URLs. When unset, a key derived from the app key (app.key, or APP_KEY) is used; with no app key either, a random per-process key, so signed URLs do not survive a restart.

§shutdown_grace_secs: u64

How long serve waits for in-flight requests after a shutdown signal (default 30 s).

§errors: ErrorOptions

How error bodies are rendered (http.errors).

§server: ServerOptions

The limits on connections (http.server).

§multipart: MultipartLimits

The limits on multipart/form-data forms (http.multipart).

Implementations§

Source§

impl HttpOptions

Source

pub fn rate_limit_key(&self, ip: IpAddr) -> IpAddr

The key a client’s per-IP limits are counted under: its IPv4 address, or the network of its IPv6 address (rate_limit_ipv6_prefix).

Trait Implementations§

Source§

impl Clone for HttpOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl ConfigSection for HttpOptions

Source§

const KEY: &'static str = "http"

The section key, a dotted path into the configuration ("billing", "mail.smtp").
Source§

fn validate(&self) -> Result<(), String>

Checks the deserialized values; an error fails the boot, naming KEY. The message must not echo secret values.
Source§

fn defaults() -> Option<Value>

The values the section has when nothing configures it, as JSON, for config:show --defaults. Leave out credentials: None (the default) publishes nothing. defaults_of builds it from Default and Serialize for a section that has no secret field.
Source§

fn schema() -> Option<SectionSchema>

What the section says about itself: its fields, their types, rustdoc, credentials and environment fallbacks. None (the default) for a section written by hand; #[derive(ConfigSection)] fills it in.
Source§

impl ConfigTable for HttpOptions

Source§

fn fields() -> Vec<FieldSchema>

The fields, in the order they are declared.
Source§

fn to_json(&self) -> Value

The value as JSON, field by field, for the defaults: credentials are null, a value of a type the description does not know is its Debug text.
Source§

impl Debug for HttpOptions

Source§

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

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

impl Default for HttpOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for HttpOptions

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

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<P> ClientModuleOptions for P
where P: ConfigSection + Clone,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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