Skip to content

CGI modules need automatic chunked transfer encoding with Keep-Alive #58

@mgrossmann

Description

@mgrossmann

Summary

CGI modules call http_printf() without setting Content-Length or Transfer-Encoding: chunked. With Connection: keep-alive, the browser waits until KEEPALIVE_TIMEOUT (~5s) because it has no way to know when the response body ends.

curl: no chunk, no close, no size. Assume close to signal end

Affected Modules

HTTPDMTT, HTTPDSRV, HTTPDM, HTTPJES2, HTTPDSL, HTTPLUA, HTTPREXX

mvsMF is not affected (sets Content-Length itself via sendDefaultHeaders()).

Root Cause

The chunked fallback is only implemented in httpget.c for static files. CGI modules take a different code path and don't get automatic chunked encoding.

Proposed Fix

The chunked fallback must happen at a central point — not just in httpget.c. When response headers have been sent without Content-Length or Transfer-Encoding, HTTPD must automatically insert Transfer-Encoding: chunked and set httpc->chunked = 1.

Option A: An http_end_headers() function that all code paths (httpget.c, CGI modules) pass through before sending body data. This function checks whether Content-Length or chunked is set, and inserts the chunked header if needed.

Option B: In httpsend.c — when the first data chunk is sent and neither content_length_set nor chunked is set, automatically send the Transfer-Encoding: chunked header and switch to chunked mode.

Important: HTTP/1.0 clients must not receive chunked encoding (as before).

Acceptance Criteria

  • CGI responses include Transfer-Encoding: chunked
  • Browser renders CGI pages immediately, no timeout waiting
  • mvsMF continues to use Content-Length
  • Static files continue to use Content-Length
  • HTTP/1.0 clients do not receive chunked encoding

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions