NPRPC docs

class RpcBuilderHttp

C++

class RpcBuilderHttp : public RpcBuilderBase

HTTP, WebSocket, HTTP/3 and WebTransport settings; see RpcBuilderBase::with_http.

The max_*_per_second limits are token buckets per client IP or session: rate tokens a second, holding at most burst (0 = rate).

include/nprpc/nprpc.hpp:853

Constructors

explicit RpcBuilderHttp(std::shared_ptr<impl::BuildConfig> cfg)

include/nprpc/nprpc.hpp:857

Methods

RpcBuilderHttp &allow_origins(std::initializer_list<std::string_view> origins) noexcept

Browser origins allowed to call cross-origin, e.g. {"https://app.example.com"}. Replaces any earlier list.

include/nprpc/nprpc.hpp:865

RpcBuilderHttp &enable_http3() noexcept

Also serves HTTP/3 and WebTransport on the same port (UDP). Needs ssl().

include/nprpc/nprpc.hpp:947

RpcBuilderHttp &enable_if_http3(bool condition) noexcept

enable_http3() when condition holds.

include/nprpc/nprpc.hpp:939

RpcBuilderHttp &http3_workers(size_t count) noexcept

Set the number of dedicated HTTP/3 worker sockets/threads. Pass 0 to auto-size from hardware concurrency; default: 4.

include/nprpc/nprpc.hpp:1030

RpcBuilderHttp &max_http3_connections_per_ip(size_t count) noexcept

Limits concurrent HTTP/3 connections per client IP.

include/nprpc/nprpc.hpp:1037

RpcBuilderHttp &max_http3_new_connections_per_ip_per_second(size_t rate, size_t burst = 0) noexcept

Limits new HTTP/3 connections per client IP.

include/nprpc/nprpc.hpp:1044

RpcBuilderHttp &max_http_rpc_requests_per_ip_per_second(size_t rate, size_t burst = 0) noexcept

Limits RPC-over-HTTP requests per client IP.

include/nprpc/nprpc.hpp:904

RpcBuilderHttp &max_request_body_size(size_t bytes) noexcept

Largest HTTP request body accepted.

include/nprpc/nprpc.hpp:973

RpcBuilderHttp &max_websocket_message_size(size_t bytes) noexcept

Largest WebSocket message accepted.

include/nprpc/nprpc.hpp:1016

RpcBuilderHttp &max_websocket_requests_per_session_per_second(size_t rate, size_t burst = 0) noexcept

Limits calls per WebSocket session.

include/nprpc/nprpc.hpp:1004

RpcBuilderHttp &max_websocket_sessions_per_ip(size_t count) noexcept

Limits concurrent WebSocket sessions per client IP.

include/nprpc/nprpc.hpp:987

RpcBuilderHttp &max_websocket_upgrades_per_ip_per_second(size_t rate, size_t burst = 0) noexcept

Limits new WebSocket connections per client IP.

include/nprpc/nprpc.hpp:994

RpcBuilderHttp &max_webtransport_connects_per_ip_per_second(size_t rate, size_t burst = 0) noexcept

Limits new WebTransport sessions per client IP.

include/nprpc/nprpc.hpp:1054

RpcBuilderHttp &max_webtransport_message_size(size_t bytes) noexcept

Largest WebTransport message accepted.

include/nprpc/nprpc.hpp:1023

RpcBuilderHttp &max_webtransport_requests_per_session_per_second(size_t rate, size_t burst = 0) noexcept

Limits calls per WebTransport session.

include/nprpc/nprpc.hpp:1064

RpcBuilderHttp &max_webtransport_stream_opens_per_session_per_second(size_t rate, size_t burst = 0) noexcept

Limits streams opened per WebTransport session.

include/nprpc/nprpc.hpp:1074

RpcBuilderHttp &root_dir(std::string_view root_dir) noexcept

Directory served as static files, from an in-memory cache. Also where Rpc::produce_host_json() writes by default.

include/nprpc/nprpc.hpp:966

RpcBuilderHttp &shm_egress_channel(std::string_view egress_channel, std::string_view ingress_channel) noexcept

Enable SHM channel offload via npquicrouter.

egress_channel
Name used to open /nprpc_<name>_s2c — Http3Server writes GSO batches there instead of calling sendmsg directly. Must match "http3_shm_channel" in npquicrouter's config.json.
ingress_channel
Name used to open /nprpc_<name>_c2s — Http3Server reads incoming QUIC datagrams from there instead of recvmsg. Must match the route's "shm_channel" in npquicrouter's config.json.

include/nprpc/nprpc.hpp:895

RpcBuilderHttp &ssl(std::string_view cert_file, std::string_view key_file, std::string_view dhparams_file = "") noexcept

Serves HTTPS/WSS (and HTTP/3) with this certificate chain and key, both PEM. See also watch_certificates and reload_certificates.

include/nprpc/nprpc.hpp:915

RpcBuilderHttp &watch_certificates(std::chrono::seconds interval) noexcept

Poll the certificate and key files every interval and reload them in-process when they change on disk, so a certbot renewal is picked up without a restart. Zero (the default) disables polling; the certificate can still be reloaded on demand with reload_certificates(), which is the better fit when certbot can run a --deploy-hook.

include/nprpc/nprpc.hpp:931

RpcBuilderHttp &watch_files() noexcept

Enable inotify-based cache invalidation for the HTTP root directory. Any file updated under root_dir() is immediately evicted from the cache so the next request serves the fresh version from disk. Useful during development (e.g. after npm run build). On non-Linux platforms this is a no-op; mtime polling handles staleness.

include/nprpc/nprpc.hpp:882

RpcBuilderHttp &websocket_compression(bool enabled = true) noexcept

Negotiates permessage-deflate on WebSocket connections.

include/nprpc/nprpc.hpp:980

RpcBuilderHttp &with_page_handler(PageHandler handler) noexcept

Render pages in this process.

handler is consulted for every GET/HEAD/POST the RPC endpoint did not claim. Returning std::nullopt falls through to the server's normal routing, so static assets keep their zero-copy path.

include/nprpc/nprpc.hpp:958