server(sse): stop sending Connection: keep-alive on the streaming endpoints - #426
Open
jamesburton wants to merge 1 commit into
Open
server(sse): stop sending Connection: keep-alive on the streaming endpoints#426jamesburton wants to merge 1 commit into
jamesburton wants to merge 1 commit into
Conversation
…points (#422) Connection is a hop-by-hop, connection-specific header field: RFC 9113 8.2.2 forbids it over HTTP/2 and HTTP/3, and it is redundant over HTTP/1.1 where persistent connections are already the default. Kestrel filters it on HTTP/2, so nothing observable breaks today, but a strict intermediary in the path need not be as forgiving, and its presence reads as intentional to anyone copying the pattern into a new endpoint. Both OpenAI-compatible streaming endpoints now configure their response through a shared internal SseResponse.ApplyHeaders, which sets the two headers SSE actually needs (text/event-stream and Cache-Control: no-cache) and documents why Connection is deliberately absent, so it has one place to not be re-added. Adds SseResponseHeaderTests as the regression guard.
There was a problem hiding this comment.
Pull request overview
Removes the illegal/redundant Connection: keep-alive header from the OpenAI-compatible SSE streaming endpoints to avoid malformed responses over HTTP/2+ (and reduce the chance the pattern gets copied into new endpoints). Consolidates SSE header setup into a single shared helper and adds a regression test.
Changes:
- Removed
Connectionheader emission from/v1/chat/completionsand/v1/completionsstreaming responses. - Introduced
SseResponse.ApplyHeaders(HttpContext)as the single shared place to apply SSE-required headers (Content-Type,Cache-Control) and document whyConnectionmust not be set. - Added a unit test guarding the expected SSE headers and asserting
Connectionis absent.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/DotLLM.Server/Endpoints/ChatCompletionEndpoint.cs | Routes streaming response header setup through SseResponse.ApplyHeaders and stops setting Connection. |
| src/DotLLM.Server/Endpoints/CompletionEndpoint.cs | Routes streaming response header setup through SseResponse.ApplyHeaders and stops setting Connection. |
| src/DotLLM.Server/Endpoints/SseResponse.cs | New shared internal helper that applies SSE headers and documents the Connection header prohibition. |
| tests/DotLLM.Tests.Unit/Server/SseResponseHeaderTests.cs | Regression tests asserting required SSE headers are set and Connection is not emitted. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Connectionis a hop-by-hop, connection-specific header field. RFC 9113 §8.2.2 forbids it overHTTP/2 and HTTP/3 (an endpoint MUST treat a message containing connection-specific header fields as
malformed), and over HTTP/1.1 it is merely redundant since persistent connections are the default.
Both OpenAI-compatible streaming endpoints were setting it.
Kestrel filters it on HTTP/2, so nothing observable breaks in the common configuration — which is
why it went unnoticed. It matters when a strict intermediary is in the path, and it reads as
intentional to anyone copying the pattern into a new endpoint, which is how it reached the Anthropic
endpoint in #326.
Changes
ChatCompletionEndpoint.HandleStreamingAsyncandCompletionEndpoint.HandleStreamingAsyncnolonger set
Connection.SseResponse.ApplyHeaders, whichsets the two headers SSE actually needs (
text/event-stream,Cache-Control: no-cache) andcarries the note on why
Connectionis deliberately absent. One place for it to not be re-added,rather than a comment repeated per endpoint.
tests/DotLLM.Tests.Unit/Server/SseResponseHeaderTests.cs— regression guard asserting the headeris absent and the other two are set, in the pattern used by server: Anthropic-compatible Messages API (/v1/messages) (#325) #326's
AnthropicStreamingTests.Written self-contained since that branch is not merged.
Verification
Closes #422