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. -
A
GETand aHEADof the archive view, and aGETof the ref listing, ignoreAuthorization. -
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 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, with the raw keypatternand a percent-decoded value in which+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. No query is an empty list, which selects all refs. The checks come in this order:- A method other than
GET,HEADincluded, gets 405 withAllow: GET. - A bad pair, an entry over the limits of one entry, an entry that
ostrya::RefSelector::parserefuses, and a query of more than 256 pairs (ostrya::MAX_REF_PATTERNS), get 400. An entry given two times 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. Each error of the build gets 500. A 400, a 405, a 500, and a 503 have an empty body. A 200 carries
Content-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.
-
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. The server also serves a client that presents no certificate.
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.