feat: add concurrent connection limits

Signed-off-by: hgshreyas <hgshreyas.cs24@bmsce.ac.in>
This commit is contained in:
hgshreyas committed 2026-08-09 17:27:47 +05:30
1 parent 1030109efa
commit 9e5e5cffe9
9 files changed
+28 -3

No files matched your search

+2
View File
@@ -56,6 +56,8 @@ function bunSocket(ws: BunServerWebSocket): WsSocket {
* Serve a Green Tea app on Bun: HTTP + SSE via app.fetch, WebSocket via Bun's server-level
* websocket handler. The ServerWebSocket only exists in open(), so per-connection state
* (inbound channel, abort, WsRequest) is stashed on ws.data during the upgrade.
* Bun.serve exposes no equivalent to Node's server.maxConnections; enforce connection caps at
* the deployment platform or reverse proxy.
*/
export function serveBun(app: App, options?: BunServeShortOptions): BunServer {
return Bun.serve({
+2
View File
@@ -31,6 +31,8 @@ declare const Deno: {
/**
* Serve a Green Tea app on Deno: HTTP + SSE via app.fetch, WebSocket via Deno.upgradeWebSocket.
* WebSocket messages flow through app.upgrade over the shared neutral core.
* Deno.serve exposes no equivalent to Node's server.maxConnections; enforce connection caps at
* the deployment platform or reverse proxy.
*/
export function serveDeno(app: App, options?: DenoServeOptions): DenoHttpServer {
return Deno.serve(options ?? {}, (request, info) => {
+1
View File
@@ -59,6 +59,7 @@ export function createHttpServer(
const server: http.Server = (opts?.tls
? nodeHttps.createServer(opts.tls as https.ServerOptions, handler)
: nodeHttp.createServer(handler)) as unknown as http.Server;
server.maxConnections = opts?.limits?.maxConnections ?? 1000;
server.requestTimeout = opts?.limits?.requestTimeoutMs ?? 30_000;
server.headersTimeout = opts?.limits?.headersTimeoutMs ?? 10_000;
server.keepAliveTimeout = opts?.limits?.keepAliveTimeoutMs ?? 5_000;
+1
View File
@@ -8,6 +8,7 @@ import type { StaticResolver } from '../views';
/** Per-request size and timeout ceilings applied by the server. */
export interface RequestLimits {
maxBodyBytes?: number; // default 1_000_000
maxConnections?: number;
requestTimeoutMs?: number; // default 30_000
headersTimeoutMs?: number; // default 10_000
keepAliveTimeoutMs?: number; // default 5_000