pub struct HttpReceiver { /* private fields */ }
Implementations§
Source§impl HttpReceiver
impl HttpReceiver
Sourcepub fn new<T: AsRef<str>>(host: T) -> Self
pub fn new<T: AsRef<str>>(host: T) -> Self
Creates a new HttpReceiver
instance bound to the specified host address. Example: 127.0.0.1:8080
.
Sourcepub fn tls<T: AsRef<Path>>(
self,
tls_server_cert_path: T,
tls_server_key_path: T,
) -> Self
pub fn tls<T: AsRef<Path>>( self, tls_server_cert_path: T, tls_server_key_path: T, ) -> Self
Enables TLS for incoming connections using the provided server certificate and private key in .pem
format and
configures the TLS context and sets supported ALPN protocols to allow HTTP/2 and HTTP/1.1.
Sourcepub fn route<T, Fut, S>(self, path: S, callback: T) -> Selfwhere
T: Fn(String, HttpRequest) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HttpResponse> + Send + 'static,
S: AsRef<str>,
pub fn route<T, Fut, S>(self, path: S, callback: T) -> Selfwhere
T: Fn(String, HttpRequest) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HttpResponse> + Send + 'static,
S: AsRef<str>,
Registers a route with a path, associating it with a handler callback.
Sourcepub fn on_event<T, Fut>(self, handler: T) -> Self
pub fn on_event<T, Fut>(self, handler: T) -> Self
Registers an asynchronous event handler callback for incoming HttpReceiverEventSignal
s.
This sets up a background task that listens for system signals (SIGTERM, SIGINT) and incoming events from the internal event channel.
Sourcepub async fn receive(self)
pub async fn receive(self)
Starts the HTTP server and begins listening for incoming TCP connections (optionally over TLS).
This method binds to the configured host address and enters a loop to accept new TCP connections. It also listens for system termination signals (SIGINT, SIGTERM) to gracefully shut down the server.