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 a receive policy, the server also runs
8//! the receive endpoint of a push. A host with its own HTTP router mounts
9//! that endpoint as a [`ReceiveEndpoint`] and authenticates the requests
10//! itself. The server also answers `GET /_ostrya/refs/v1` with the bytes of
11//! [`ostrya::Repo::build_ref_listing`] for the ref patterns of its query. The
12//! crate builds on Linux alone.
13//!
14//! # Entry points
15//!
16//! - [`serve`] binds the listeners of a [`ServeOptions`] and runs the server.
17//! - [`bind`] binds the listeners and returns a [`Server`] to run with [`Server::run`].
18//! - [`ServeOptions`] holds the addresses, the TLS files, and the options of a push.
19//! - [`ReceiveEndpoint::new`] creates the receive endpoint for the router of a host.
20//! - [`ReceiveEndpoint::handle`] answers one request of the endpoint.
21//! - [`ReceiveAuth`] is the authentication of the endpoint by its host.
22//! - [`Error`] is the error of each fallible operation of the crate.
23//!
24//! # Features
25//!
26//! - `smol` (default): the `smol` backend of `ostrya-rt`.
27//! - `tokio`: the `tokio` backend of `ostrya-rt`, for a host on tokio.
28//!
29//! # Examples
30//!
31//! ```no_run
32//! use ostrya::Repo;
33//! use ostrya_server::{ServeOptions, bind};
34//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
35//! let repo = Repo::open("/srv/repo".as_ref()).await?;
36//! let mut opts = ServeOptions::default();
37//! opts.listen = vec!["0.0.0.0:8080".parse()?];
38//! let server = bind(repo, opts).await?;
39//! println!("listening on {:?}", server.local_addrs());
40//! server.run().await?;
41//! # Ok(())
42//! # }
43//! ```
44
45mod auth;
46mod body;
47mod endpoint;
48mod error;
49mod options;
50mod receive;
51mod receive_auth;
52mod refs;
53mod request;
54mod router;
55mod server;
56mod session;
57mod shutdown;
58mod stall;
59
60pub use body::ReceiveBody;
61pub use endpoint::{EndpointOptions, ReceiveEndpoint};
62pub use error::{Error, Result};
63pub use options::{ServeOptions, ServerTls};
64pub use receive_auth::{ReceiveAuth, Refusal, RequestKind, SessionSetup};
65pub use server::{Server, bind, serve};