Repository navigation
Flush forwarded event streams so SSE reaches the client as it arrives - #44
Merged
andrew merged 1 commit intoOct 2, 2026
Conversation
andrew
approved these changes
Oct 2, 2026
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.
Closes #43
Problem
Proxy.serveForwardrelays the upstream body with a bareio.Copy(w, resp.Body)and never flushes. On the inspected forward path, a server-sent event stream therefore collects in the server's output buffer (about 4KB) instead of reaching the client as each event arrives. CONNECT tunnels are unaffected becausepipecopies raw bytes.This came up in alpha-omega-security/scrutineer#1103, where model traffic for
-model-proxymoves from a CONNECT tunnel to an inspected forward through this proxy. Scrutineer works around it today by wrapping theResponseWriteritself, but every consumer of the forward path has the same problem.Fix
serveForwardnow callscopyResponseBody:text/event-stream, or a body of unknown length withContentLength == -1): the headers are flushed first, then the body is flushed after every read.io.Copy, so ordinary downloads behave exactly as before.This follows the rule
httputil.ReverseProxyuses to decide when to flush immediately. It reuses the existingegressCopyBufbuffer size and adds only the standard librarymimeimport, so there are no new dependencies.Testing
TestEgressProxy_ForwardStreamsEventStreamputs a real proxy listener between a client and an SSE upstream. The upstream withholds its second event until the client has read the first, so a buffering proxy times out instead of passing. It fails against the previousio.Copy(5s timeout) and passes with this change.TestStreamingResponsecovers which responses are flushed: event streams with and without parameters, unknown-length bodies and known-length bodies.go mod verify,go mod tidy -diff,gofmt,go vet(default andintegrationtags),golangci-lint run(0 issues),go test -race ./...(egress coverage 90.8%) andgovulncheckall pass locally.Follow-up
Once a harness release includes this, scrutineer can upgrade and drop its
flushingResponseWriterworkaround from #1103.