Implement HTTP/1.1 persistent connections. Biggest performance win — reduces TCP handshakes for multi-resource page loads by 80%+.
Description
REQUEST_VERSION evaluation, idle timeout, request counter, worker pool exhaustion mitigation.
Files to edit
src/httprese.c — Evaluate REQUEST_VERSION: HTTP/1.1 + no Connection: close → keepalive=1; HTTP/1.0 + Connection: keep-alive → keepalive=1; else → keepalive=0. If keepalive: transition to CSTATE_IN instead of CSTATE_CLOSE. Increment request_count, close if >= keepalive_max. Reset per-request state but keep socket open.
src/httpin.c — Add idle timeout between requests using selectex() with configurable timeout. No data within keepalive_timeout → CSTATE_CLOSE.
src/httpresp.c — Send Connection: keep-alive or Connection: close header based on keepalive state.
include/httpd.h — Add keepalive (UCHAR), request_count (USHRT) to HTTPC (existing unused bytes). Add cfg_keepalive_timeout, cfg_keepalive_max to HTTPD.
Worker pool exhaustion mitigation
- Short idle timeout (5s default)
- keepalive_max limit (100 requests)
- Worker pool auto-scales (mintask → maxtask)
Acceptance criteria
- Browser DevTools show connection reuse (single TCP for HTML+CSS+JS+images)
- Connection closes after keepalive_timeout idle
- Connection closes after keepalive_max requests
- HTTP/1.0 clients get
Connection: close
- Worker pool does not deadlock under 9+ concurrent connections
- mvsMF works identically (no changes needed)
Notion task: TSK-8
Implement HTTP/1.1 persistent connections. Biggest performance win — reduces TCP handshakes for multi-resource page loads by 80%+.
Description
REQUEST_VERSION evaluation, idle timeout, request counter, worker pool exhaustion mitigation.
Files to edit
src/httprese.c— Evaluate REQUEST_VERSION: HTTP/1.1 + noConnection: close→ keepalive=1; HTTP/1.0 +Connection: keep-alive→ keepalive=1; else → keepalive=0. If keepalive: transition to CSTATE_IN instead of CSTATE_CLOSE. Increment request_count, close if >= keepalive_max. Reset per-request state but keep socket open.src/httpin.c— Add idle timeout between requests using selectex() with configurable timeout. No data within keepalive_timeout → CSTATE_CLOSE.src/httpresp.c— SendConnection: keep-aliveorConnection: closeheader based on keepalive state.include/httpd.h— Addkeepalive(UCHAR),request_count(USHRT) to HTTPC (existing unused bytes). Addcfg_keepalive_timeout,cfg_keepalive_maxto HTTPD.Worker pool exhaustion mitigation
Acceptance criteria
Connection: closeNotion task: TSK-8