Repository navigation
fix(indy): stream over Indy without Content-Length: 0 - #636
Draft
edsontmarques wants to merge 1 commit into
Draft
edsontmarques wants to merge 1 commit into
edsontmarques wants to merge 1 commit into
Conversation
THorseWebBrokerStreamWriter sent "Content-Length: 0" on Indy, so the
client ended a SendStream response at the header; in chunked mode the
response carried both Content-Length and Transfer-Encoding. Indy writes
a Content-Length unless the response declares a non-identity
Transfer-Encoding, so on Indy every stream is now chunked, SSE
included: the writer declares chunked to Indy, sends no Content-Length
and drops the duplicate custom Transfer-Encoding header. The chunked
decision became a virtual method computed once in the constructor;
other WebBroker hosts keep the previous rule.
tests/indy-stream passes on Delphi 10.2 (Indy 10.6.2.5366) and fails
against the previous source ("must not carry Content-Length").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem and change
On Delphi with an Indy provider (Console, VCL, Daemon),
SendStreamdoes not deliver its body.THorseWebBrokerStreamWriter.SendRawHeaderssetsFResponseInfo.ContentLength := 0beforeWriteHeader, so the response goes out withContent-Length: 0:text/event-stream, the client ends the response at the header, and the events arrive outside any response or are lost;Content-Length: 0andTransfer-Encoding: chunked. RFC 9112 §6.2 says a sender MUST NOT send both, and a strict client rejects the response.Changing
0to-1is not enough. WithContentLength = -1and no non-identityTransferEncoding, Indy'sTIdHTTPResponseInfo.WriteHeadercomputes the length itself: fromContentText, or fromContentStream.Size(0 for the empty stream set here). With neither, it sends its default HTML page. Indy only skips the length when the response declares a non-identityTransfer-Encoding.This patch makes every stream chunked on Indy, SSE included.
EventSourceaccepts chunked SSE, and the Indy server speaks HTTP/1.1.UsesChunkedTransfer, computed once in the writer's constructor. The base keeps the previous rule.THorseWebBrokerStreamWriterreturnsTrueonly when the raw response is aTIdHTTPAppResponse. Other WebBroker hosts (ISAPI, CGI, Apache) keep the previous rule, so IIS or Apache do not frame the chunks twice.TransferEncoding := 'chunked'andContentLength := -1. AfterMoveCookiesAndCustomHeaders, it removes theTransfer-Encodingcustom header added bySendHeaders, because Indy appends custom headers without removing duplicates. The emptyContentStreamis no longer set, so Indy writes nothing after the final chunk.doc/streaming.md(English and Portuguese) gains a note on Indy providers.No new protected field is touched: the change uses the existing
TIdHTTPAppResponseFriend.Validation performed
tests/indy-streamruns the real Console provider withKeepConnectionAliveon and reads the wire with a raw TCP client. It covers four cases:text/event-stream: three events;text/plain: three parts;Sendon the same connection after the stream;Sendon its own.A streaming response must carry no
Content-Lengthand a singleTransfer-Encoding: chunked, and its body must decode from the chunks.tests/indy-stream, Delphi 10.2 Tokyo (compiler 32.0), Indy 10.6.2.5366, Windows, ConsolePASS-HorseSource)/sse: a streaming response must not carry Content-Length (got "0")tests.yml(FPC 3.3.1, Linux x86_64),stream-factoryincludedI ran the Delphi check on our fork, which carries the same change on top of other patches. The diff applied to
masterwithout conflicts in this area. Reproduce on Windows:Validation still needed
-Provider VCL) and the Linux Daemon: not run.🤖 Generated with Claude Code