pub struct Server {
pub app_state: AppState,
pub http_addr: Option<SocketAddr>,
pub https_addr: Option<SocketAddr>,
}Expand description
HTTP(S) server.
Fields§
§app_state: AppState§http_addr: Option<SocketAddr>§https_addr: Option<SocketAddr>Implementations§
Source§impl Server
impl Server
Sourcepub async fn new(config: Config) -> ServerResult<Self>
pub async fn new(config: Config) -> ServerResult<Self>
Resolve listener addresses and build the server shell.
Also compiles Rhai middlewares listed in
config.service.middlewares_file_paths. Compilation happens here
(not in the config crate) because the compiled artefact is a
runtime object — see the server-level module docstring.
Sourcepub async fn bind_http(&self) -> ServerResult<Option<TcpListener>>
pub async fn bind_http(&self) -> ServerResult<Option<TcpListener>>
Bind the HTTP listener without accepting connections yet.
Returns Ok(None) if no HTTP listener is configured, Ok(Some(_))
on a successful bind, or Err if the bind itself failed — this is
the piece http_start used to swallow via log::error! + early
return, with no way for a caller to observe it.
Splitting bind from serve exists for callers (namely the
integration-test harness) that need the two to be separate steps:
bind, read back the real port via local_addr() (useful when
[listener].port is 0 and the OS assigns one), then hand the
same listener to Server::serve_http. Because it’s the same
listener throughout, there is no window between “port known” and
“port held” for another process to take it.
Sourcepub async fn serve_http(&self, listener: TcpListener)
pub async fn serve_http(&self, listener: TcpListener)
Accept connections forever on an already-bound HTTP listener.
Sourcepub async fn bind_https(
&self,
) -> ServerResult<Option<(TcpListener, TlsAcceptor)>>
pub async fn bind_https( &self, ) -> ServerResult<Option<(TcpListener, TlsAcceptor)>>
Bind the HTTPS listener (including loading TLS material) without
accepting connections yet. See Server::bind_http for why this
is split from serving.
Every failure this used to swallow via log::error! + early
return - missing TLS config, unreadable cert/key, a TLS config
that fails to build, or the bind itself - now surfaces as Err.
Sourcepub async fn serve_https(&self, listener: TcpListener, acceptor: TlsAcceptor)
pub async fn serve_https(&self, listener: TcpListener, acceptor: TlsAcceptor)
Accept connections forever on an already-bound HTTPS listener.