Skip to main content

Module keepalive_hint

Module keepalive_hint 

Source
Expand description

Connection: keep-alive hint middleware.

Adds explicit Connection: keep-alive and Keep-Alive: timeout=N, max=M response headers when enabled via the MOCKFORGE_HTTP_KEEPALIVE_HINT environment variable (or the --http-keepalive-hint CLI flag, when wired).

This is a workaround for proxies that:

  • Speak HTTP/1.0 upstream by default (hyper closes the connection after one response unless the request carried Connection: keep-alive).
  • Cache the keep-alive policy from the response headers rather than the HTTP version. F5/Avi/HAProxy in some configurations look at the Keep- Alive response header to decide whether to pool the upstream socket.

Issue #79 — Srikanth’s round-3 reply: proxy observed FIN from MockForge after every 200 response, then RST when it reused the socket. Root cause is upstream HTTP/1.1 not being negotiated. We can’t force hyper to keep the connection alive after an HTTP/1.0 request, but we can advertise our preferred policy in the response so proxies that read it adjust.

Functions§

is_keepalive_hint_enabled
Is the keepalive hint enabled? Reads MOCKFORGE_HTTP_KEEPALIVE_HINT once per startup process. Truthy values: 1, true, yes, on.
keepalive_hint_middleware
Middleware: stamp Connection: keep-alive and Keep-Alive: timeout=…, max=… on every response. Does NOT override an upstream-set Connection: close header.