Expand description
Phase 81.33.b.real Stage 2 — daemon-side plugin HTTP proxy.
Plugins declare [plugin.http] mount_prefix = "/<prefix>" in
their nexo-plugin.toml. The daemon builds a
PluginHttpRouter from every declaring plugin’s manifest at
boot, and the HTTP handler checks the router on every incoming
request BEFORE the legacy hardcoded /whatsapp/* etc. paths.
A match forwards the request to the plugin’s subprocess via
broker JSON-RPC (plugin.<id>.http.request), reads the reply,
and writes it back to the TCP stream.
§Wire format
See crate::plugin_http crate docs for the JSON shape.
Briefly:
- request payload:
{ method, path, query, headers: [[k,v],…], body_base64 } - reply payload:
{ status, headers: [[k,v],…], body_base64 }
§Limitations
- No streaming responses (SSE, chunked transfer). Plugin must buffer the full response before replying.
- No WebSocket upgrades. WebSocket endpoints stay on
[plugin.http_server](plugin binds its own port). - Body bytes are base64-encoded JSON; OK for HTML pages (≤100KB typical) but wasteful for large uploads.
Structs§
- Http
Section View - View struct mirroring
nexo_plugin_manifest::http::PluginHttpSectionbut without the cross-crate dep (router crate already depends on nexo-plugin-manifest so this is mostly cosmetic — kept here so downstream alternative impls can avoid the dep if needed). - Plugin
Http Response - Plugin-side reply parsed from the broker RPC.
- Plugin
Http Router - Longest-prefix-first matcher. Insertion preserves declaration
order until
Self::sortis called; once sorted, prefix matching is deterministic for ambiguous prefixes (e.g./api/v1wins over/api).
Enums§
- Plugin
Http Forward Error - Typed forwarder errors. Caller renders the right status code:
- Route
Registration Error - Route registration error. Returned by
PluginHttpRouter::registerwhen the requestedmount_prefixviolates a reserved-prefix or validation rule.
Constants§
- RESERVED_
PREFIXES - Daemon-reserved path prefixes. Plugin registrations whose
mount_prefixcollides with any of these are rejected so a malicious or buggy plugin cannot hijack health/metrics/admin surfaces.
Traits§
- DynPlugin
Manifest - Type-erased view of a plugin’s manifest sufficient for router
construction. The real
NexoPlugintrait lives in nexo-core; pulling it into this crate would create a circular dep. The caller (daemon) walkswire.plugin_handlesand wraps each handle in a small impl of this trait OR — simpler — passes aVec<(plugin_id, mount_prefix, timeout)>directly toPluginHttpRouter::registerin a loop.
Functions§
- build_
router_ from_ handles - Build a router from a slice of
(plugin_id, manifest). Skips plugins whose manifest does not declare[plugin.http]. - forward_
request - Forward a daemon-received HTTP request to the plugin via broker JSON-RPC.