feat: automatic chunked transfer encoding for CGI responses#59
Merged
mgrossmann merged 1 commit intomainfrom Apr 11, 2026
Merged
feat: automatic chunked transfer encoding for CGI responses#59mgrossmann merged 1 commit intomainfrom
mgrossmann merged 1 commit intomainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Transfer-Encoding: chunkedinhttpprtv.cwhen the header-ending blank line is sent without Content-Length or chunked for HTTP/1.1 clientsContent-Length:headers from any caller (including external CGI modules like mvsMF)httpget.c— now handled centrallyrdwflag inhttprese.cfor keep-alive request cyclingHow it works
httpprtv.cis the central printf path all code uses (HTTPD core + CGI modules via HTTPX vector). When it sees:Content-Length:header → setscontent_length_setflag"\r\n", 2 bytes) → checks if chunked fallback is neededTransfer-Encoding: chunkedheader, enables chunk framingTest plan
make build && make link)Transfer-Encoding: chunkedContent-Length(not chunked)Content-LengthFixes #58