#[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 ofcredentialsby the SHA-256 digest of the token. An empty token matches no line. - A Basic credential,
Authorization: Basicwith the base64 ofNAME:TOKEN. It matches the line ofNAMEby 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:
- A request with more than one
Authorizationheader gets 401. - If the connection has no TLS, a bearer or Basic credential gets 403,
unless
allow_cleartext_credentialsis set. This check also applies where anonymous push is allowed. - An
Authorizationheader that matches no line gets 401, also when the request has a client certificate. - A request with no
Authorizationheader 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:NAMEfor a bearer token or a Basic credential, whereNAMEis the name of its credential line.cert:HEXfor a client certificate, whereHEXis the SHA-256 digest of its DER bytes in lowercase hex.anonymousfor 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
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: DurationThe 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: boolThe 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: boolThe 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: u32The number of object streams of one session, as in
EndpointOptions::parallel_uploads.
The default is 4.
session_idle_timeout: DurationThe idle timeout of a session, as in
EndpointOptions::session_idle_timeout.
The default is 300 seconds.
max_sessions: usizeThe 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
impl Clone for ServeOptions
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>.
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>.