Skip to content

fix: do not set Connection header on SSE responses - #2117

Merged
johanandren merged 1 commit into
akka:mainfrom
max8github:fix-sse-connection-header
Oct 23, 2026
Merged

johanandren merged 1 commit into
akka:mainfrom
max8github:fix-sse-connection-header

Conversation

@max8github

@max8github max8github commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

HttpResponses.serverSentEvents* set Connection: keep-alive on every SSE response. The Connection header is not allowed for HTTP/2, so Akka HTTP ignores it and logs this each time an SSE endpoint is served over HTTP/2:

WARN Explicitly set HTTP header 'Connection: keep-alive' is ignored, `Connection` header is not allowed for HTTP/2

HTTP/1.1 keeps connections alive by default, so the header is not needed. This removes it.

Reproduced with a minimal service on SDK 3.5.16: an SSE endpoint called over HTTP/2 logged the warning; a plain endpoint and SSE over HTTP/1.1 did not. The stream still delivered all events.

@patriknw

Copy link
Copy Markdown
Contributor

Do not commit with

Co-Authored-By: Claude

@patriknw patriknw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good

@patriknw

Copy link
Copy Markdown
Contributor

This is in line with the standards:

  • HTTP/2 (RFC 9113 §8.2.2): a server must not send Connection or other connection-specific headers in HTTP/2. A message that contains one counts as malformed. Akka HTTP already drops the header and logs the warning (HttpMessageRendering.scala:170). HTTP/3 has the same rule.
  • HTTP/1.1 (RFC 9112 §9.3): connections stay open by default. keep-alive is an HTTP/1.0 option.
  • Proxies: Connection is a hop-by-hop header (RFC 9110 §7.6.1), so any compliant proxy removes it before the response reaches the end client.
  • SSE spec: the WHATWG spec does not require a Connection header. Only Content-Type: text/event-stream matters, and the PR keeps that and Cache-Control: no-cache.

@johanandren johanandren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix is fine, some smaller things to clean up

The Connection header is not allowed for HTTP/2. Akka HTTP drops it and
logs a warning for every SSE response served over HTTP/2.
@max8github
max8github force-pushed the fix-sse-connection-header branch from c3ec0ca to fc52887 Compare October 23, 2026 09:15

@johanandren johanandren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johanandren
johanandren merged commit 1cf256c into akka:main Oct 23, 2026
34 checks passed
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.

3 participants