feat: Make ACCEPTS header parsing follow specification more closely#36
Merged
Conversation
mcollina
requested changes
May 12, 2026
Member
Author
|
@mcollina do you think optimization was sufficient? |
Member
Author
|
@mcollina could you please rereview? hot path is now faster than it was before the PR |
Member
Author
|
@mcollina how can we proceed with that? or you prefer not to do this change altogether? |
mcollina
approved these changes
Jun 9, 2026
mcollina
left a comment
Member
There was a problem hiding this comment.
lgtm
Sorry, I lost all the notifications
|
Hi, any sign of a release with these changes included? |
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.
Per RFC 9110 §12.5.1 (https://www.rfc-editor.org/rfc/rfc9110#name-accept), a wildcard Accept header (/, text/*) or a missing Accept header means any media type is acceptable, including
text/event-stream. The server gets to choose.@fastify/ssecurrently treats those headers as "not SSE" and falls through to the route's regular handler. For SSE-only routes the regular handler is the same handler that uses reply.sse, and reply.sse is undefined on the fallback path, so the request 500s with a crypticTypeError: Cannot read properties of undefined (reading 'send').That hits anything that doesn't send an explicit
text/event-streamheader: Postman defaults, curl defaults, fetch() defaults, plain navigations.After this PR, routes can now declare their intent up front:
text/event-stream,text/*,*/*, missing) admits SSE. Clients that explicitly refuse SSE (Accept:application/json, ortext/event-stream;q=0) get 406 Not Acceptable.text/event-streamtoken routes to SSE; everything else (including /) reaches the handler with reply.sse undefined, so the handler can serve a non-SSE response. This preserves the convention that wildcards prefer the richer non-SSE representation when the route offers a choice.sse: trueroutes behave exactly as before - the existing fallback pattern, the existing tests, and the documented examples all keep working. New routes can opt into the explicit kinds without affecting old ones.Safe for a minor bump pre-1.0: no behavioral change for any existing
sse: trueregistration; only additive surface ('only', 'dual', the object form's kind field).Checklist
npm run test && npm run benchmark --if-present