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.

  • With receive policies, the server identifies the client of each request by the steps of Authentication, after the check of the method. A GET and a HEAD of the archive view, and a GET of the ref listing, get the status of a refusal, 401 or 403, with an empty body and Content-Length: 0. A 401 carries the two WWW-Authenticate headers. 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 ReadAccess of the item, as ArchiveView and Repo::build_ref_listing state. A path that the client cannot read gets the 404 of an absent path.

  • summary and summary.sig give the files of the summary of the item of the client, which Repo::regenerate_summaries writes. An item with no summary gets 404. When the .access file 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 one ServerEvent::StaleSummary for 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 carry Cache-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 anonymous item 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, and refs/remotes/ is not. summary and summary.sig give the files of the summary of the anonymous item 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 of Repo::build_ref_listing. The path must match exactly, and the server reads its query. Each pair of the query is pattern=VALUE, an entry of the local refs, or collection=VALUE, an entry of the collection refs by ID/NAME. The raw key is pattern or collection, and the value is percent-decoded, with + that 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 pattern pair is an empty list, which selects all local refs. With one or more collection pairs, the listing holds the selected collection refs in ostree.summary.collection-map. With none, it holds no collection ref. The checks come in this order:

    1. A method other than GET, HEAD included, gets 405 with Allow: GET.
    2. The server identifies the client. A refusal gets its status.
    3. A bad pair, a pair with another key, an entry over the limits of one entry, an entry that ostrya::RefSelector::parse refuses, 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.
    4. 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::ReadFailed to ServeOptions::on_event. For each directory under refs/mirrors/ whose name fails the collection-id rule, the server reports one ServerEvent::InvalidCollectionDir to ServeOptions::on_event in 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 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. The server reports one ServerEvent::ReadFailed to ServeOptions::on_event for the request. The event names the method, the path of the request as the client sent it, and the error, for example EACCES on an object. A body that fails after the status 200 gives no event.

  • 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. 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

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§

§

impl !Freeze for Server

§

impl !RefUnwindSafe for Server

§

impl !UnwindSafe for Server

§

impl Forget for Server

§

impl Move for Server

§

impl Send for Server
where RawVecInner: Send, Arc<Async<TcpListener>>: Send, Arc<ArchiveView>: Send, Arc<RepoInner>: Send, Arc<Clients>: Send, Arc<Listings>: Send, Mutex<HashSet<String>>: Send, Arc<dyn Fn(&ServerEvent) + Sync + Send>: Send, Arc<ServerConfig>: Send,

§

impl Sync for Server
where RawVecInner: Sync, Arc<Async<TcpListener>>: Sync, Arc<ArchiveView>: Sync, Arc<RepoInner>: Sync, Arc<Clients>: Sync, Arc<Listings>: Sync, Mutex<HashSet<String>>: Sync, Arc<dyn Fn(&ServerEvent) + Sync + Send>: Sync, Arc<ServerConfig>: Sync,

§

impl Unpin for Server
where *const u8 is !null: Unpin, Arc<Async<TcpListener>>: Unpin, Arc<ArchiveView>: Unpin, Arc<RepoInner>: Unpin, Arc<Clients>: Unpin, Arc<Listings>: Unpin, Align4<u32>: Unpin, Align1<u8>: Unpin, Arc<dyn Fn(&ServerEvent) + Sync + Send>: Unpin, Arc<ServerConfig>: Unpin,

§

impl UnsafeUnpin for Server
where *const u8 is !null: UnsafeUnpin, PhantomData<TcpListener>: UnsafeUnpin, PhantomData<SocketAddr>: UnsafeUnpin, *const ArcInner<ArchiveView> is !null: UnsafeUnpin, PhantomData<ArcInner<ArchiveView>>: UnsafeUnpin, *const ArcInner<RepoInner> is !null: UnsafeUnpin, PhantomData<ArcInner<RepoInner>>: UnsafeUnpin, *const ArcInner<Clients> is !null: UnsafeUnpin, PhantomData<ArcInner<Clients>>: UnsafeUnpin, *const ArcInner<Listings> is !null: UnsafeUnpin, PhantomData<ArcInner<Listings>>: UnsafeUnpin, Align4<u32>: UnsafeUnpin, Align1<u8>: UnsafeUnpin, PhantomData<(String, ())>: UnsafeUnpin, *const ArcInner<dyn Fn(&ServerEvent) + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&ServerEvent) + Sync + Send>>: UnsafeUnpin, *const ArcInner<ServerConfig> is !null: UnsafeUnpin, PhantomData<ArcInner<ServerConfig>>: UnsafeUnpin,

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