pub struct Server { /* private fields */ }Expand description
A server with its listeners bound, ready to run.
§HTTP behavior
-
The server answers
GETandHEAD, except on the ref listing. Outside the receive endpoint and the ref listing, another method gets 405 withAllow: GET, HEAD. -
With a receive endpoint, a request under the raw path prefix
/_ostrya/receive/v1/goes to the endpoint if its method is notGETorHEAD. AGETor aHEADunder the prefix goes to the archive view and gets 404. -
With receive policies, the server identifies the client of each request by the steps of Authentication, after the check of the method. A
GETand aHEADof the archive view, and aGETof the ref listing, get the status of a refusal, 401 or 403, with an empty body andContent-Length: 0. A 401 carries the twoWWW-Authenticateheaders. Claims that do not parse refuse each read with 403, as Claims states. -
The server serves the archive view and the ref listing with the
ReadAccessof the item, asArchiveViewandRepo::build_ref_listingstate. A path that the client cannot read gets the 404 of an absent path. -
summaryandsummary.siggive the files of the summary of the item of the client, whichRepo::regenerate_summarieswrites. An item with no summary gets 404. When the.accessfile of the item holds another digest than the access digest of the item, or does not exist while the file exists, the request gets 404, and the server reports oneServerEvent::StaleSummaryfor each item in the life of the server. The server computes the digests at start, and reads the files for each request, so a new write of the summaries takes effect while the server runs. A 200 and a 404 of these two paths carryCache-Control: private, because the body depends on the client. A 401 and a 403 do not. -
With no receive policies, the server identifies no client. Each read gets the rights of the
anonymousitem under the implicit group of a config with no client group, with the collection id of the repository. Each local ref and each mirror ref of another collection are served, andrefs/remotes/is not.summaryandsummary.siggive the files of the summary of theanonymousitem of this implicit group. -
The HTTP layer removes a
#fragment before the routing, so the server does not see a fragment. -
The server percent-decodes the request path. Outside the ref listing, it ignores the query. If the path has a bad escape, a NUL, or bytes that are not UTF-8, the response is 404. The server decodes the path after it identifies the client.
-
The server answers the raw path
/_ostrya/refs/v1, with and without a receive endpoint, with the bytes ofRepo::build_ref_listing. The path must match exactly, and the server reads its query. Each pair of the query ispattern=VALUE, an entry of the local refs, orcollection=VALUE, an entry of the collection refs byID/NAME. The raw key ispatternorcollection, and the value is percent-decoded, with+that stays+. The value is one entry of aostrya::RefSelector: a ref pattern with an optional leading!. An entry has at mostostrya::MAX_REF_ENTRY_PARTSparts andostrya::MAX_REF_ENTRY_LENbytes. Nopatternpair is an empty list, which selects all local refs. With one or morecollectionpairs, the listing holds the selected collection refs inostree.summary.collection-map. With none, it holds no collection ref. The checks come in this order:- A method other than
GET,HEADincluded, gets 405 withAllow: GET. - The server identifies the client. A refusal gets its status.
- A bad pair, a pair with another key, an entry over the limits of one
entry, an entry that
ostrya::RefSelector::parserefuses, and a query of more than 256 pairs of the two keys together (ostrya::MAX_REF_PATTERNS), get 400. An entry given two times for one key counts two times, and the server keeps it one time. - If 4 listings are in flight over all connections, the request gets
503 with
Retry-After: 1. A listing is in flight from the start of its build until its response body drops.
Then the server builds the listing with the read rights of the client. Each error of the build gets 500, and the server reports one
ServerEvent::ReadFailedtoServeOptions::on_event. For each directory underrefs/mirrors/whose name fails the collection-id rule, the server reports oneServerEvent::InvalidCollectionDirtoServeOptions::on_eventin the life of the server, and the listing leaves out the directory. A 400, a 405, a 500, and a 503 have an empty body. A 200 carriesContent-Length, and the server sends the body in frames of at most 64 KiB under the body timeout. - A method other than
-
A path that the view does not find gets 404 with an empty body. A path that the view refuses gets the same response, so a client cannot tell a private path from an absent one.
-
If the view returns an error, the response is 500 with an empty body. The server reports one
ServerEvent::ReadFailedtoServeOptions::on_eventfor the request. The event names the method, the path of the request as the client sent it, and the error, for exampleEACCESon an object. A body that fails after the status 200 gives no event. -
A response with a known length carries
Content-Length. A.filezbuilt on request carries noContent-Length. -
The server reads a file of the archive view in frames of at most 64 KiB, and never collects the file whole. The server builds a ref listing whole in memory, at most
ostrya::MAX_REF_LISTINGbytes, and sends it in frames of at most 64 KiB. -
A
HEADtakes the answer ofArchiveView::head, which reads no byte of the file. For a.filezbuilt on request, it reads no xattr and does no deflate work. -
Plain HTTP serves HTTP/1.1. Over TLS, ALPN selects HTTP/2 or HTTP/1.1. An HTTP/2 connection carries at most 32 streams at the same time. It takes a header list of at most 32 KiB for one request, counted as the name, the value, and 32 bytes of each header field. A larger list gets 431.
-
A TLS handshake has 30 seconds to complete. An HTTP/1.1 connection has 30 seconds to send the headers of each request.
-
With a receive endpoint, the HTTP/2 windows are the windows of
ReceiveEndpoint::h2_windows. A read-only server keeps the windows of hyper. -
If a response body waits longer than
ServeOptions::body_timeoutfor the client, the server ends its connection. If an HTTP/2 peer does not answer a ping within that time, the server ends the connection. -
A body that streams gives at most 256 KiB in one run of polls. Then it yields to the executor.
-
With a client CA, the server verifies a client certificate against the CA. A client that presents no certificate also completes the handshake, and the other auth items identify it.
-
With
ServeOptions::proxy_protocol, each listener reads a PROXY protocol header, version 1 or 2, at the start of each connection, before the TLS handshake. A connection with no valid header, or with no header within 30 seconds, closes with no response. The bytes after the header go to the TLS handshake or to the HTTP layer. -
The server reads the client address, the scheme, and a forwarded certificate from the headers of a trusted proxy, for each request. Client address and Forwarded certificate state the rules.
Implementations§
Source§impl Server
impl Server
Sourcepub fn local_addrs(&self) -> &[SocketAddr]
pub fn local_addrs(&self) -> &[SocketAddr]
Returns the address of each listener, in the order of the options.
If the options give port 0, the address holds the port that the kernel chose.
Sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Serves connections until the future drops.
Each listener accepts in a task of its own. The idle sweep of the sessions runs in a task of its own. If an accept fails, the listener accepts again after 100 ms.
When the future drops, the server closes the listeners and ends each connection that it accepted. It also stops the receive endpoint, which aborts each session that does not commit. The session rules of the endpoint state the other effects.
§Errors
The future never completes, so it returns no error.