Skip to content

feat: automatic chunked transfer encoding for CGI responses#59

Merged
mgrossmann merged 1 commit intomainfrom
issue-58-cgi-chunked-fallback
Apr 11, 2026
Merged

feat: automatic chunked transfer encoding for CGI responses#59
mgrossmann merged 1 commit intomainfrom
issue-58-cgi-chunked-fallback

Conversation

@mgrossmann
Copy link
Copy Markdown
Contributor

Summary

  • Auto-inject Transfer-Encoding: chunked in httpprtv.c when the header-ending blank line is sent without Content-Length or chunked for HTTP/1.1 clients
  • Auto-detect Content-Length: headers from any caller (including external CGI modules like mvsMF)
  • Remove explicit chunked logic from httpget.c — now handled centrally
  • Reset rdw flag in httprese.c for keep-alive request cycling

How it works

httpprtv.c is the central printf path all code uses (HTTPD core + CGI modules via HTTPX vector). When it sees:

  1. A Content-Length: header → sets content_length_set flag
  2. The header-ending blank line ("\r\n", 2 bytes) → checks if chunked fallback is needed
  3. If HTTP/1.1 and no Content-Length/chunked → injects Transfer-Encoding: chunked header, enables chunk framing

Test plan

  • Build on MVS (make build && make link)
  • CGI pages (HTTPDSRV, HTTPDM, HTTPDMTT) show Transfer-Encoding: chunked
  • Browser renders CGI pages immediately, no timeout waiting
  • mvsMF API responses still use Content-Length (not chunked)
  • Static files with known size still use Content-Length
  • Static files without known size (SSI) use chunked
  • HTTP/1.0 clients receive no chunked encoding
  • Keep-alive works correctly across multiple requests

Fixes #58

CGI modules send response bodies via http_printf() without setting
Content-Length or Transfer-Encoding. With keep-alive, clients wait
until KEEPALIVE_TIMEOUT because they cannot detect the end of the
response body.

Add automatic chunked fallback in httpprtv.c (the central printf
path all code uses):
- Auto-detect Content-Length headers and set the tracking flag
- When the header-ending blank line is sent, check if neither
  Content-Length nor chunked is set for HTTP/1.1 clients
- If so, inject Transfer-Encoding: chunked before the blank line
  and enable chunk framing for subsequent body data
- Use httpc->rdw as headers_ended flag to prevent re-triggering

Remove explicit chunked logic from httpget.c — now handled
transparently by httpprtv for all code paths.

Reset rdw flag in httprese.c for keep-alive request cycling.

Fixes #58
@mgrossmann mgrossmann merged commit c71d6ef into main Apr 11, 2026
1 check failed
@mgrossmann mgrossmann deleted the issue-58-cgi-chunked-fallback branch April 11, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CGI modules need automatic chunked transfer encoding with Keep-Alive

1 participant