Skip to main content

Module plugin_http

Module plugin_http 

Source
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§

HttpSectionView
View struct mirroring nexo_plugin_manifest::http::PluginHttpSection but 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).
PluginHttpResponse
Plugin-side reply parsed from the broker RPC.
PluginHttpRouter
Longest-prefix-first matcher. Insertion preserves declaration order until Self::sort is called; once sorted, prefix matching is deterministic for ambiguous prefixes (e.g. /api/v1 wins over /api).

Enums§

PluginHttpForwardError
Typed forwarder errors. Caller renders the right status code:
RouteRegistrationError
Route registration error. Returned by PluginHttpRouter::register when the requested mount_prefix violates a reserved-prefix or validation rule.

Constants§

RESERVED_PREFIXES
Daemon-reserved path prefixes. Plugin registrations whose mount_prefix collides with any of these are rejected so a malicious or buggy plugin cannot hijack health/metrics/admin surfaces.

Traits§

DynPluginManifest
Type-erased view of a plugin’s manifest sufficient for router construction. The real NexoPlugin trait lives in nexo-core; pulling it into this crate would create a circular dep. The caller (daemon) walks wire.plugin_handles and wraps each handle in a small impl of this trait OR — simpler — passes a Vec<(plugin_id, mount_prefix, timeout)> directly to PluginHttpRouter::register in 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.