Skip to main content

ostrya_server/
lib.rs

1#![forbid(unsafe_code)]
2
3//! The HTTP server of ostrya, for the pull and the push of one repository.
4//!
5//! A [`Server`] serves one repository to the pull of the `ostree` command and
6//! of ostrya. The pull reads it as an `archive` repository, whatever its mode
7//! (see [`ostrya::ArchiveView`]). With the client groups of the repository
8//! ([`ostrya::ReceivePolicies`]), the server identifies the client of each
9//! request by the auth items of the groups. It serves each read with the
10//! read rights of the item ([`ostrya::access::ReadAccess`]), and runs the
11//! receive endpoint of a push, which gives each session the policy of one
12//! group. With no client groups, each read gets the rights of the
13//! `anonymous` item under the implicit group. Behind a
14//! proxy, it reads the PROXY protocol header of a connection, and the client
15//! address, the scheme, and the client certificate that a trusted proxy
16//! forwards in the request headers. A host with
17//! its own HTTP router mounts that endpoint as a [`ReceiveEndpoint`] and
18//! authenticates the requests itself. The server also answers `GET /_ostrya/refs/v1` with the bytes of
19//! [`ostrya::Repo::build_ref_listing`] for the ref patterns of its query, of
20//! the local refs and of the collection refs, and the read rights of its
21//! client. The crate builds on Linux alone.
22//!
23//! # Entry points
24//!
25//! - [`serve`] binds the listeners of a [`ServeOptions`] and runs the server.
26//! - [`bind`] binds the listeners and returns a [`Server`] to run with [`Server::run`].
27//! - [`ServeOptions`] holds the addresses, the TLS files, the client CA, the proxy settings, and the options of a push.
28//! - [`ReceiveEndpoint::new`] creates the receive endpoint for the router of a host.
29//! - [`ReceiveEndpoint::handle`] answers one request of the endpoint.
30//! - [`ReceiveAuth`] is the authentication of the endpoint by its host.
31//! - [`ServerEvent`] is an event that the server reports to its host.
32//! - [`Error`] is the error of each fallible operation of the crate.
33//!
34//! # Features
35//!
36//! - `smol` (default): the `smol` backend of `ostrya-rt`.
37//! - `tokio`: the `tokio` backend of `ostrya-rt`, for a host on tokio.
38//!
39//! # Examples
40//!
41//! ```no_run
42//! use ostrya::Repo;
43//! use ostrya_server::{ServeOptions, bind};
44//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
45//! let repo = Repo::open("/srv/repo".as_ref()).await?;
46//! let mut opts = ServeOptions::default();
47//! opts.listen = vec!["0.0.0.0:8080".parse()?];
48//! let server = bind(repo, opts).await?;
49//! println!("listening on {:?}", server.local_addrs());
50//! server.run().await?;
51//! # Ok(())
52//! # }
53//! ```
54
55mod auth;
56mod body;
57mod cert;
58mod endpoint;
59mod error;
60mod event;
61mod forwarded;
62mod options;
63mod proxy_protocol;
64mod receive;
65mod receive_auth;
66mod refs;
67mod request;
68mod router;
69mod server;
70mod session;
71mod shutdown;
72mod stall;
73#[cfg(test)]
74mod test_pki;
75
76pub use body::ReceiveBody;
77pub use endpoint::{EndpointOptions, ReceiveEndpoint};
78pub use error::{Error, Result};
79pub use event::ServerEvent;
80pub use options::{ServeOptions, ServerTls};
81pub use receive_auth::{ReceiveAuth, Refusal, RequestKind, SessionSetup};
82pub use server::{Server, bind, serve};