Repository navigation
Avoid parsing the Accept header on non-SSE SignalR connection GETs - #70190
Merged
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Both changed files were inspected, but no frozen review bundle was supplied to verify head/base identities, routed guidance, or existing-feedback deduplication.
No open issues 🎉
What changed in this PR
This PR reduces unnecessary Accept-header parsing in SignalR’s HTTP connection dispatcher by adding a raw-header prefilter for server-sent events (SSE) detection.
Changes:
- Skips typed-header parsing when no Accept value contains
event-stream, retaining the original parsed check for potential matches. - Adds 19 test cases comparing detection with the original expression, covering casing, whitespace, multiple values, parameters, and malformed entries.
| File | Description |
|---|---|
| src/SignalR/common/Http.Connections/test/ServerSentEventsRequestDetectionTests.cs | Adds equivalence tests for SSE request detection. |
| src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs | Adds and uses the raw Accept-header prefilter. |
Review effort: Balanced
Member
|
/review |
halter73
approved these changes
Nov 3, 2026
halter73
temporarily deployed
to
copilot-pat-pool
November 3, 2026 20:05 — with
GitHub Actions
Inactive
halter73
temporarily deployed
to
copilot-pat-pool
November 3, 2026 20:05 — with
GitHub Actions
Inactive
halter73
temporarily deployed
to
copilot-pat-pool
November 3, 2026 20:07 — with
GitHub Actions
Inactive
halter73
temporarily deployed
to
copilot-pat-pool
November 3, 2026 20:09 — with
GitHub Actions
Inactive
halter73
temporarily deployed
to
copilot-pat-pool
November 3, 2026 20:10 — with
GitHub Actions
Inactive
halter73
temporarily deployed
to
copilot-pat-pool
November 3, 2026 20:11 — with
GitHub Actions
Inactive
Contributor
|
✅ No documentation PR was created. Confidence that documentation is needed: 3% No docs needed: internal performance optimization with identical behavior and no public API changes. Documentation surfaces considered
|
halter73
temporarily deployed
to
copilot-pat-pool
November 3, 2026 20:12 — with
GitHub Actions
Inactive
This branch was previously 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.
HttpConnectionDispatcher.ExecuteAsynchandles every GET to a connection endpoint, which includes each long-polling poll and each WebSocket upgrade. On every one of those GETs it calledGetTypedHeaders().Accept, which parses the wholeAcceptheader intoMediaTypeHeaderValues, just to check fortext/event-stream.Change
The new
IsServerSentEventsRequestfirst scans the rawAcceptvalues for the substringevent-stream(OrdinalIgnoreCase). It runs the original typed-header check only when that substring is present.A parsed media type that equals
text/event-streamrequires the raw header to contain the contiguous ASCII tokenevent-stream. So the prefilter can only produce false positives, and those fall through to the unchanged original check. Behavior is identical. There are no public API or wire changes.Results
Side-by-side BenchmarkDotNet run on a
DefaultHttpContext, 3 rounds (TypedParse is the current code, Prefilter is this PR):*/*text/html,...,*/*;q=0.8)text/event-stream(once per SSE connection)Hot GET paths, meaning every long-poll and every WebSocket upgrade, are 8–34× faster and allocation-free. The SSE GET happens only once per connection and costs about 40 ns more.
Tests
Added
ServerSentEventsRequestDetectionTests. It covers 19 Accept shapes, including case and whitespace variants, multiple values, parameters, invalid entries and near-miss subtypes. Each case asserts that the new method matches the original typed-header expression.Microsoft.AspNetCore.Http.Connections.Tests: 315 passed, 7 skipped.🤖 Posted by ASP.NET Core Perf 2 (AI Agent)