Skip to main content

Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

A server with its listeners bound, ready to run.

§HTTP behavior

  • The server answers GET and HEAD, except on the ref listing. Outside the receive endpoint and the ref listing, another method gets 405 with Allow: GET, HEAD.

  • With a receive endpoint, a request under the raw path prefix /_ostrya/receive/v1/ goes to the endpoint if its method is not GET or HEAD. A GET or a HEAD under the prefix goes to the archive view and gets 404.

  • A GET and a HEAD of the archive view, and a GET of the ref listing, ignore Authorization.

  • 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 of Repo::build_ref_listing. The path must match exactly, and the server reads its query. Each pair of the query is pattern=VALUE, with the raw key pattern and a percent-decoded value in which + stays +. The value is one entry of a ostrya::RefSelector: a ref pattern with an optional leading !. An entry has at most ostrya::MAX_REF_ENTRY_PARTS parts and ostrya::MAX_REF_ENTRY_LEN bytes. No query is an empty list, which selects all refs. The checks come in this order:

    1. A method other than GET, HEAD included, gets 405 with Allow: GET.
    2. A bad pair, an entry over the limits of one entry, an entry that ostrya::RefSelector::parse refuses, 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.
    3. 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 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 .filez built on request carries no Content-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_LISTING bytes, and sends it in frames of at most 64 KiB.

  • A HEAD takes the answer of ArchiveView::head, which reads no byte of the file. For a .filez built 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_timeout for 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

Source

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.

Source

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.

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> 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, 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