NPRPC docs

class RpcBuilderHttp

Swift

final class RpcBuilderHttp

HTTP/WebSocket-specific builder with SSL and page-rendering options

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:333

Methods

@discardableResult func allowOrigins(_ origins: [String]) -> RpcBuilderHttp

Allow browser cross-origin requests from the provided HTTPS origins.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:398

@discardableResult func cacheControl(_ pattern: String, _ value: String) -> RpcBuilderHttp

Send value as the Cache-Control of static files whose request path matches pattern (HTTP/1.1 and HTTP/3). First matching rule wins; unmatched files get public, max-age=3600; an empty value sends no Cache-Control. A pattern without "/" matches the file name in any directory (*.html), one with "/" the whole path (/assets/**); * stays within a path segment, ** crosses them, ? is one character.

.cacheControl("/assets/**", "public, max-age=31536000, immutable")
.cacheControl("*.html", "no-cache")

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:482

@discardableResult func compression(_ enabled: Bool = true, minSize: UInt = 256) -> RpcBuilderHttp

Compress HTTP/1.1 and HTTP/3 responses (br/gzip/deflate, per Accept-Encoding): static text-like files and page-handler responses of at least minSize bytes.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:466

@discardableResult func enableHttp3() -> RpcBuilderHttp

Enable HTTP/3 support

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:365

@discardableResult func enableWebSocketCompression(_ enabled: Bool = true) -> RpcBuilderHttp

Enable or disable WebSocket permessage-deflate negotiation.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:423

@discardableResult func http3IdleTimeout(milliseconds: UInt32) -> RpcBuilderHttp

QUIC idle timeout the HTTP/3 server announces (max_idle_timeout): a connection with nothing sent for the shorter of this and the client's value is dropped. Zero announces no timeout, so only the client's applies. Default: 30 s.

milliseconds
idle timeout in milliseconds

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:457

@discardableResult func http3ShmChannels(egress egressChannel: String, ingress ingressChannel: String) -> RpcBuilderHttp

Configure shared memory channels for npquicrouter integration.

The router recreates its rings each time it starts. The server checks once a second and reattaches, logging a warning, so the two can restart in any order.

egressChannel
Matches "shm_egress_channel" in npquicrouter's config.json.
ingressChannel
Matches the route's "shm_ingress_channel" in npquicrouter's config.json.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:575

@discardableResult func http3Workers(_ count: UInt) -> RpcBuilderHttp

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

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:445

@discardableResult func keepAliveTimeout(seconds: UInt32) -> RpcBuilderHttp

How long an HTTP/1.1 connection may stay idle between requests before it is closed. Zero turns keep-alive off: every response closes the connection.

seconds
idle timeout in seconds

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:416

@discardableResult func maxHttp3ConnectionsPerIp(_ count: UInt) -> RpcBuilderHttp

Cap concurrently active HTTP/3 connections per client IP.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:512

@discardableResult func maxHttp3NewConnectionsPerIpPerSecond(_ rate: UInt, burst: UInt = 0) -> RpcBuilderHttp

Limit new HTTP/3 connection attempts per client IP.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:519

@discardableResult func maxHttpRpcRequestsPerIpPerSecond(_ rate: UInt, burst: UInt = 0) -> RpcBuilderHttp

Limit HTTP RPC requests per client IP across HTTP/1.1 and HTTP/3.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:527

@discardableResult func maxRequestBodySize(_ bytes: UInt) -> RpcBuilderHttp

Cap buffered HTTP request bodies before dispatch.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:405

@discardableResult func maxWebSocketMessageSize(_ bytes: UInt) -> RpcBuilderHttp

Cap inbound WebSocket message size.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:430

@discardableResult func maxWebSocketRequestsPerSessionPerSecond(_ rate: UInt, burst: UInt = 0) -> RpcBuilderHttp

Limit request messages received on a single WebSocket session.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:504

@discardableResult func maxWebSocketSessionsPerIp(_ count: UInt) -> RpcBuilderHttp

Cap concurrently active WebSocket sessions per client IP.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:489

@discardableResult func maxWebSocketUpgradesPerIpPerSecond(_ rate: UInt, burst: UInt = 0) -> RpcBuilderHttp

Limit WebSocket upgrade attempts per client IP.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:496

@discardableResult func maxWebTransportConnectsPerIpPerSecond(_ rate: UInt, burst: UInt = 0) -> RpcBuilderHttp

Limit WebTransport CONNECT requests per client IP.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:535

@discardableResult func maxWebTransportMessageSize(_ bytes: UInt) -> RpcBuilderHttp

Cap inbound WebTransport control/native payload size.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:437

@discardableResult func maxWebTransportRequestsPerSessionPerSecond(_ rate: UInt, burst: UInt = 0) -> RpcBuilderHttp

Limit WebTransport framed requests per session.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:543

@discardableResult func maxWebTransportStreamOpensPerSessionPerSecond(_ rate: UInt, burst: UInt = 0) -> RpcBuilderHttp

Limit WebTransport child stream opens per session.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:551

@discardableResult func rootDir(_ path: String) -> RpcBuilderHttp

Set HTTP document root directory

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:391

@discardableResult func ssl(certFile: String, keyFile: String, dhparamsFile: String = "") -> RpcBuilderHttp

Enable SSL/TLS for HTTP and WebSocket

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:342

@discardableResult func watchCertificates(intervalSeconds interval: UInt32) -> RpcBuilderHttp

Poll the certificate and key files and reload them in-process when either changes 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 Rpc.reloadCertificates(), which is the better fit when certbot can run a deploy hook.

interval
seconds between checks

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:358

@discardableResult func watchFiles() -> RpcBuilderHttp

Enable inotify-based cache invalidation on the HTTP root directory. Any file written or renamed under rootDir() is immediately evicted from the file cache so the next request reloads it from disk. Useful during development — no effect on non-Linux platforms.

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:562

@discardableResult func withPageHandler(_ handler: @escaping PageHandler) -> RpcBuilderHttp

Render pages in this process.

handler is consulted for every GET/HEAD/POST the RPC endpoint did not claim. Returning nil falls through to static file serving, so assets keep their zero-copy path.

.withPageHandler { request in
    guard request.path == "/blog" else { return nil }
    let page = Int(request.queryItems["page"] ?? "1") ?? 1
    return PageResponse(html: renderBlog(page))
}

nprpc_swift/Sources/NPRPC/RpcBuilder.swift:384