Documentation
¶
Overview ¶
Package webhook provides a process-wide hub that routes incoming HTTP webhook requests to registered handlers. Webhook trigger nodes register a path on the hub when they start; the HTTP server forwards matching requests to them. This is the bridge that lets trigger nodes (which only receive a Start(ctx, out) call) react to external HTTP requests without owning a listener themselves.
Index ¶
Constants ¶
const (
// PathPrefix is where webhook endpoints are mounted on the HTTP server.
PathPrefix = "/webhooks/"
)
Variables ¶
var DefaultHub = NewHub()
DefaultHub is the process-wide hub shared by webhook trigger nodes and the HTTP server.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub routes incoming webhook requests to handlers keyed by path.
func (*Hub) Dispatch ¶
Dispatch delivers a request to the handler registered for its path and returns its result; ok is false if no handler is registered.
func (*Hub) HandlerFunc ¶
func (h *Hub) HandlerFunc() http.HandlerFunc
HandlerFunc returns an http.HandlerFunc that parses the request and dispatches it to the hub based on the path following PathPrefix. The response status reflects the outcome: 404 unknown path, 400 unreadable body, 413 body over 1 MiB, then the handler's Result (200/401/405/503).
func (*Hub) Register ¶
Register binds a handler to a path. It errors if the path is already taken, so two flows can't silently fight over the same webhook URL.
func (*Hub) Unregister ¶
Unregister removes the handler for a path.
type Request ¶
type Request struct {
Method string
Path string
Query map[string][]string
Headers map[string]string
Body interface{}
RemoteAddr string
Token string
}
Request is the normalized representation of an incoming webhook HTTP request delivered to a registered handler.
Credentials are kept out of Headers and Query, which end up in flow payloads (and from there in logs, files, notifications): Cookie, Authorization, X-Webhook-Token and X-PiWorker-* headers and the "token" query parameter are removed. The webhook token, if any, is passed in Token instead (X-Webhook-Token header first, then ?token=).
type Result ¶
type Result int
Result is a handler's verdict on a request; the hub maps it to the HTTP status the caller sees.
const ( // Accepted: the request was queued into the flow (200). Accepted Result = iota Unauthorized // MethodNotAllowed: the node filters on another method (405). MethodNotAllowed // Dropped: the flow is stopping or its queue is full (503), so the // sender knows to retry instead of assuming delivery. Dropped )