Skip to main content

ServeOptions

Struct ServeOptions 

Source
#[non_exhaustive]
pub struct ServeOptions { pub listen: Vec<SocketAddr>, pub tls: Option<ServerTls>, pub body_timeout: Duration, pub receive: Option<Arc<ReceivePolicy>>, pub allow_anonymous_push: bool, pub credentials: Option<Vec<u8>>, pub allow_cleartext_credentials: bool, pub parallel_uploads: u32, pub session_idle_timeout: Duration, pub max_sessions: usize, pub on_report: Option<Arc<dyn Fn(ReceiveReport) + Send + Sync>>, }
Expand description

The options of bind.

The struct is #[non_exhaustive], so a caller starts from ServeOptions::default and sets the fields.

The fields parallel_uploads, session_idle_timeout, max_sessions, and on_report go to the EndpointOptions of the receive endpoint. Their defaults are the defaults of EndpointOptions::default. If receive is None, bind does not read these four fields, allow_anonymous_push, credentials, or allow_cleartext_credentials. It then refuses no value of them.

§Authentication

The server runs the receive endpoint with built-in authentication methods. Each session gets the policy of receive and no hooks. The methods are:

  • A bearer token, Authorization: Bearer TOKEN. It matches a line of credentials by the SHA-256 digest of the token. An empty token matches no line.
  • A Basic credential, Authorization: Basic with the base64 of NAME:TOKEN. It matches the line of NAME by the digest of the token. The token runs from the first : to the end, so it can hold :. A credential with no :, a name that is not UTF-8, and an empty token match no line.
  • A client certificate that the TLS handshake verified against the client CA of tls.
  • allow_anonymous_push, for a request with no credential.

bind refuses an endpoint with no method. If the server has no TLS, bind also refuses an endpoint whose one method is the credential file, unless allow_cleartext_credentials is set. No request can pass that method, because the endpoint refuses each credential over plain HTTP.

The server compares the digest of a request with the digest of each line in constant time. It does not stop at a match. The checks run in this order:

  1. A request with more than one Authorization header gets 401.
  2. If the connection has no TLS, a bearer or Basic credential gets 403, unless allow_cleartext_credentials is set. This check also applies where anonymous push is allowed.
  3. An Authorization header that matches no line gets 401, also when the request has a client certificate.
  4. A request with no Authorization header gets the first result that applies:
    • the owner of its client certificate
    • the owner anonymous, if anonymous push is allowed
    • 401, if the server has credential lines
    • 403, if the client CA is the one method of the server

Each 401 of the built-in methods carries two headers: WWW-Authenticate: Bearer realm="ostrya" and WWW-Authenticate: Basic realm="ostrya".

The owner key of a request has a prefix for each method:

  • token:NAME for a bearer token or a Basic credential, where NAME is the name of its credential line.
  • cert:HEX for a client certificate, where HEX is the SHA-256 digest of its DER bytes in lowercase hex.
  • anonymous for anonymous push.

A name can be equal to a digest, so the prefix keeps the keys of two methods apart. A bearer token and a Basic credential of one line give one key.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§listen: Vec<SocketAddr>

The addresses to listen on.

Port 0 lets the kernel choose a port, which Server::local_addrs reports. bind refuses an empty list. The default is 127.0.0.1:8080.

§tls: Option<ServerTls>

The TLS files, or None for plain HTTP. The default is None.

§body_timeout: Duration

The longest time that a response body waits for the client to take its next bytes.

If a body waits longer, its connection ends. The bodies of the connection then drop and release the files and the compressors that they hold. An HTTP/2 connection sends a ping after half this time with no frame from the peer. It ends if the peer does not answer within this time.

A body that waits for its own reader, for example for a compressor of the archive view, does not wait for the client. The time does not count for such a body until it gives its next frame.

The default is 60 seconds. bind refuses zero.

§receive: Option<Arc<ReceivePolicy>>

The receive policy of the receive endpoint, or None for a read-only server.

The default is None. Every session of the endpoint shares the policy. The server does not read the policy or a repository setting of the endpoint again while it runs. A change takes effect at the next start.

§allow_anonymous_push: bool

The switch that lets a request with no credential push.

The default is false. The switch is one of the methods in Authentication.

§credentials: Option<Vec<u8>>

The bytes of the push credential file.

The default is None. Each line of the file holds one credential, NAME:HEX. NAME is one or more visible ASCII characters other than :. HEX is the SHA-256 digest of the secret in 64 lowercase hex digits.

A line that starts with # and an empty line hold no credential. A file with no credential line gives no authentication method.

If receive is set, bind parses the file. A read-only server does not read the field. A malformed line, a name on two lines, and a digest on two lines are Error::Credentials. This error names the line by its number and holds no byte of the line.

§allow_cleartext_credentials: bool

The switch that takes a bearer or Basic credential on a connection without TLS.

The default is false. If the switch is false, the endpoint refuses such a credential with 403. A server on a loopback address or behind a proxy that terminates TLS can set it. A read-only server does not read the field.

§parallel_uploads: u32

The number of object streams of one session, as in EndpointOptions::parallel_uploads.

The default is 4.

§session_idle_timeout: Duration

The idle timeout of a session, as in EndpointOptions::session_idle_timeout.

The default is 300 seconds.

§max_sessions: usize

The most sessions open at the same time, as in EndpointOptions::max_sessions.

The default is 16.

§on_report: Option<Arc<dyn Fn(ReceiveReport) + Send + Sync>>

The callback for the report of a committed session, as in EndpointOptions::on_report.

Trait Implementations§

Source§

impl Clone for ServeOptions

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 Debug for ServeOptions

The debug text holds no byte of the credential file. It shows the file as <N bytes redacted>, and a report callback that is set as <callback>.

Source§

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

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

impl Default for ServeOptions

Source§

fn default() -> ServeOptions

Returns the “default value” for a type. 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<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> 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