LemonChannels. InboundHttp. Router
(lemon_channels v0.1.0)
View Source
Dispatches inbound HTTP to the adapter registered for the first path segment.
Deliberately thin: parsing, dispatch, and turning an unregistered segment or a
crashing handler into a plain status code. Everything else — signature
verification, idempotency, payload shape — belongs to the adapter, because
those rules differ per provider and baking any of them in here would recreate
LemonGateway.Transports.Webhook inside lemon_channels.
Authenticate first where the handler can
A handler that can authenticate from the request line and headers alone —
a shared token, an API key — implements
LemonChannels.InboundHttp.Handler.authorized?/1, and it runs before
Plug.Parsers. Otherwise an anonymous caller can make this process read and
decode a body on every request and only then be told 401, which is free for
them and expensive here.
Not every handler can: most providers sign the raw or parsed payload, which cannot be checked before the body exists. Those omit the callback and are parsed for as before, which is why the body limit below still matters.
Body limit
LemonChannels.InboundHttp.max_body_bytes/0, 2 MB by default — well under
Plug.Parsers' 8 MB — and configurable for adapters that must accept larger
payloads. Over the limit, Plug.Parsers raises and the caller gets a 413.
The limit is resolved per request rather than frozen into the pipeline at
compile time, so a value set in config/runtime.exs or at boot is honoured
rather than silently ignored.
Summary
Functions
Callback implementation for Plug.call/2.
Callback implementation for Plug.init/1.