+//! # Proxmox REST server
+//!
+//! This module provides convenient building blocks to implement a
+//! REST server.
+//!
+//! ## Features
+//!
+//! * HTTP and HTTP2
+//! * highly threaded code, uses Rust async
+//! * static API definitions using schemas
+//! * restartable systemd daemons using `systemd_notify`
+//! * support for long running worker tasks (threads or async tokio tasks)
+//! * supports separate access and authentification log files
+//! * separate control socket to trigger management operations
+//! - logfile rotation
+//! - worker task management
+//! * generic interface to authenticate user
+
use std::sync::atomic::{Ordering, AtomicBool};
use anyhow::{bail, format_err, Error};
use tokio::fs::File;
use tokio::time::Instant;
use url::form_urlencoded;
+use tower_service::Service;
use proxmox::api::schema::{
parse_parameter_strings, parse_simple_value, verify_json_object, ObjectSchemaType,
}
/// REST server implementation (configured with [ApiConfig])
+///
+/// This struct implements the [Service] trait in order to use it with
+/// [hyper::server::Builder::serve].
pub struct RestServer {
api_config: Arc<ApiConfig>,
}
const CHUNK_SIZE_LIMIT: u64 = 32 * 1024;
impl RestServer {
+ /// Creates a new instance.
pub fn new(api_config: ApiConfig) -> Self {
Self {
api_config: Arc::new(api_config),
}
}
-impl tower_service::Service<&Pin<Box<tokio_openssl::SslStream<tokio::net::TcpStream>>>>
+impl Service<&Pin<Box<tokio_openssl::SslStream<tokio::net::TcpStream>>>>
for RestServer
{
type Response = ApiService;
}
}
-impl tower_service::Service<&hyper::server::conn::AddrStream> for RestServer {
+impl Service<&hyper::server::conn::AddrStream> for RestServer {
type Response = ApiService;
type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<ApiService, Error>> + Send>>;
}
}
-impl tower_service::Service<&tokio::net::UnixStream> for RestServer {
+impl Service<&tokio::net::UnixStream> for RestServer {
type Response = ApiService;
type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<ApiService, Error>> + Send>>;
.ok()
}
-impl tower_service::Service<Request<Body>> for ApiService {
+impl Service<Request<Body>> for ApiService {
type Response = Response<Body>;
type Error = Error;
#[allow(clippy::type_complexity)]