pub struct WebhookTriggerServer { /* private fields */ }Expand description
A minimal pure-Rust HTTP/1.1 server that listens for inbound HTTP POST
requests and dispatches them to registered WebhookTrigger handlers via
a WebhookRouter.
Uses std::net::TcpListener — no async runtime is required.
Each accepted connection is handled synchronously (blocking I/O).
§Security note
This is designed for low-volume internal webhook reception. Production deployments should sit behind a TLS-terminating reverse proxy.
Implementations§
Source§impl WebhookTriggerServer
impl WebhookTriggerServer
Sourcepub fn new(bind_addr: impl Into<String>) -> Self
pub fn new(bind_addr: impl Into<String>) -> Self
Create a new server bound to bind_addr.
The server does not start listening until start is called.
Sourcepub fn register_trigger(
&self,
workflow_id: impl Into<String>,
trigger: WebhookTrigger,
)
pub fn register_trigger( &self, workflow_id: impl Into<String>, trigger: WebhookTrigger, )
Register a webhook trigger for a workflow.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Return true if the accept loop is currently active.
Sourcepub fn start(&self) -> Result<JoinHandle<()>, Error>
pub fn start(&self) -> Result<JoinHandle<()>, Error>
Start the server, binding to the configured address.
Spawns a background thread that accepts connections. The
std::thread::JoinHandle is returned so the caller can optionally
join the thread.
§Errors
Returns std::io::Error if the TCP socket cannot be bound.
Sourcepub fn stop(&self)
pub fn stop(&self)
Stop the accept loop. The background thread will exit on its next iteration.
Sourcepub fn handle_connection(
stream: TcpStream,
router: Arc<RwLock<WebhookRouter>>,
) -> Vec<String>
pub fn handle_connection( stream: TcpStream, router: Arc<RwLock<WebhookRouter>>, ) -> Vec<String>
Handle a single HTTP/1.1 connection: parse the request, route it, and send a response.
Returns the list of workflow IDs that were triggered (for testing).
Sourcepub fn local_addr(&self) -> Result<SocketAddr, Error>
pub fn local_addr(&self) -> Result<SocketAddr, Error>
Return the actual bound address (useful when binding to port 0).
§Errors
Returns std::io::Error if the address cannot be determined.