Skip to content

feat: RFC compliant typed headers - #360

Merged
nielsenko merged 75 commits into
serverpod:mainfrom
nielsenko:feat-rfc-compliant-headers
Jun 15, 2026
Merged

nielsenko merged 75 commits into
serverpod:mainfrom
nielsenko:feat-rfc-compliant-headers

Conversation

@nielsenko

@nielsenko nielsenko commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Overhaul typed headers to be fully (/more?) RFC compliant. Parsing is still lenient (except for security related headers), but construction (and serialization) is always strict.

Related Issues

Pre-Launch Checklist

Please ensure that your PR meets the following requirements before submitting:

  • This update focuses on a single feature or bug fix. (For multiple fixes, please submit separate PRs.)
  • I have read and followed the Dart Style Guide and formatted the code using dart format.
  • I have referenced at least one issue this PR fixes or is related to.
  • I have updated/added relevant documentation (doc comments with ///), ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully.
  • I have documented any breaking changes below.

Breaking Changes

  • Includes breaking changes.
  • No breaking changes.

Many typed headers changed, both their shape (Dart interface) and semantics (behavior or parse, etc.).

Additional Notes

These changes are landing now in concert with serverpod 4.0

Summary by CodeRabbit

  • New Features

    • Exported new HTTP header type primitives: Delta Seconds, ETag Value, Header Scanner, Host, Language Tag, Origin, Parameter Value, Token, and Token Value for advanced header validation use cases.
    • Added support for multiple range units in Accept-Ranges header parsing.
    • Added optional report-to parameter support in Cross-Origin policy headers.
  • Bug Fixes & Improvements

    • Improved HTTP header parsing robustness: malformed quality values now default to 1.0 instead of causing request rejection.
    • Enhanced case-insensitive header field name handling across Accept-Control and Vary headers.
    • Strengthened RFC 9110 compliance for Transfer-Encoding, Set-Cookie, and Origin validation.
    • Fixed weak ETag handling in If-Range requests to prevent improper range request satisfaction.

@nielsenko nielsenko self-assigned this Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 884a2290-2df5-4fb8-8fc3-d15cb92f2006

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR raises the Dart SDK baseline to 3.10.3, updates CI gating to match, and refactors multiple typed HTTP header parsers and primitives to use stricter canonicalization, new parsing helpers, and revised validation semantics. Tests and IO behavior were updated to match the new header contracts.

Changes

CI and SDK baseline

Layer / File(s) Summary
Workflow and SDK version
.github/workflows/ci.yaml, pubspec.yaml
The Dart SDK floor and CI job matrices now target 3.10.3.

Typed headers and primitives

Layer / File(s) Summary
New header primitives
packages/relic_core/lib/relic_core.dart, packages/relic_core/lib/src/headers/typed/primitives/*
New primitives for tokens, hosts, language tags, origins, q-values, delta seconds, ETags, parameter values, and header scanning are added and exported.
Typed header parsing and encoding
packages/relic_core/lib/src/headers/typed/headers/*, packages/relic_core/lib/src/headers/typed/headers/util/*
Typed header implementations now use the new primitives for canonicalization, structured parsing, and encoding across cache, content, CORS, auth, and related headers.
IO range handling
packages/relic_io/lib/src/adapter/http_response_extension.dart, packages/relic_io/lib/src/io/static/static_handler.dart
The IO adapter and static file handler now consume the updated typed headers for transfer encoding and If-Range validation.
Typed header tests
packages/relic_core/test/headers/header_test.dart, packages/relic_core/test/headers/typed/*, packages/relic_core/test/message/apply_headers_test.dart, packages/relic_io/test/static/if_range_test.dart
The typed header test suites are updated to match the new parsing, encoding, canonicalization, and validation behavior.

Sequence Diagram(s)

sequenceDiagram
  participant PackageExports as relic_core.dart
  participant Parsers as typed header parsers
  participant IO as relic_io handlers
  participant Tests as typed tests
  PackageExports->>Parsers: export new primitives
  Parsers->>IO: provide parsed headers and validators
  Parsers->>Tests: expose new parse/encode behavior
  IO->>Tests: verified by range and transfer-encoding tests
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~90+ minutes

Possibly related issues

Possibly related PRs

  • serverpod/relic#159: Shares the same q-value parsing/encoding and typed header parser refactoring area in relic_core.
  • serverpod/relic#142: Directly overlaps with the HostHeader/host parsing work and the move away from Uri for host semantics.
  • serverpod/relic#318: Also changes CI coverage gating and workflow conditions in the same repository.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

@nielsenko
nielsenko force-pushed the feat-rfc-compliant-headers branch 3 times, most recently from da8791d to 9608c86 Compare June 12, 2026 08:39
@codecov

codecov Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.17935% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.72%. Comparing base (0112560) to head (843d531).

Files with missing lines Patch % Lines
...lib/src/headers/typed/primitives/language_tag.dart 84.28% 22 Missing ⚠️
...b/src/headers/typed/primitives/header_scanner.dart 91.42% 9 Missing ⚠️
...ic_core/lib/src/headers/typed/primitives/host.dart 94.48% 7 Missing ⚠️
...b/src/headers/typed/headers/set_cookie_header.dart 86.84% 5 Missing ⚠️
...ore/lib/src/headers/typed/headers/host_header.dart 81.81% 4 Missing ⚠️
...e/lib/src/headers/typed/primitives/etag_value.dart 86.66% 4 Missing ⚠️
...ore/lib/src/headers/typed/headers/util/qvalue.dart 70.00% 3 Missing ⚠️
.../lib/src/headers/typed/headers/util/report_to.dart 84.21% 3 Missing ⚠️
.../src/headers/typed/primitives/parameter_value.dart 89.28% 3 Missing ⚠️
.../headers/typed/headers/accept_encoding_header.dart 80.00% 2 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #360      +/-   ##
==========================================
+ Coverage   91.21%   91.72%   +0.51%     
==========================================
  Files          98      108      +10     
  Lines        3849     4510     +661     
  Branches     1964     2291     +327     
==========================================
+ Hits         3511     4137     +626     
- Misses        338      373      +35     
Flag Coverage Δ
relic_core 91.54% <92.13%> (+0.61%) ⬆️
relic_io 93.34% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

nielsenko added 20 commits June 12, 2026 10:48
@nielsenko
nielsenko requested a review from a team June 12, 2026 12:23

@marcelomendoncasoares marcelomendoncasoares left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving in behalf of all the agents that have already done it.

@nielsenko
nielsenko merged commit 84ec95c into serverpod:main Jun 15, 2026
29 checks passed
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 10, 2026
Backported from serverpod#360 (RFC compliant typed headers) so the header-parsing
security fixes can build on the same primitives as main. The files are
deliberately not exported from relic_core.dart: they are an implementation
detail here, and keeping them internal leaves the 1.2.x public API surface
unchanged.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 17, 2026
dart:io owns Transfer-Encoding framing and Connection handling: on a
bodyless GET it waits for a chunked body the client never sends, on
Dart 3.13+ HttpServer rejects an empty or unknown Transfer-Encoding
coding at the protocol layer, and it drops an empty Connection request
header. Ten round-trip tests hung for 30s or saw closed connections.

Backport the test-side reshaping from serverpod#360 onto the 1.2 line: the
affected Transfer-Encoding and empty-Connection cases move to direct
unit tests in relic_core against the 1.2 parse API, keeping 1.2
semantics (chunked reordering, closed directive set). No runtime code
changes.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 17, 2026
Backported from serverpod#360 (RFC compliant typed headers) so the header-parsing
security fixes can build on the same primitives as main. The files are
deliberately not exported from relic_core.dart: they are an implementation
detail here, and keeping them internal leaves the 1.2.x public API surface
unchanged.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 17, 2026
DigestAuthorizationHeader.headerValue joined the scheme into the
comma-separated param list, emitting "Digest, username=...". The old
regex parser skimmed past the junk, but the linear header scanner
rightly rejects the encoder's own output, breaking codec round-trips.

Mirror the encoder fixed on main by serverpod#360 (excluded from this backport):
a single SP after the scheme (RFC 7235 2.1), quoted-string escaping
with a control-character guard for text params, and bare tokens for
algorithm, qop, and nc.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 17, 2026
Backported from serverpod#360 (RFC compliant typed headers) so the header-parsing
security fixes can build on the same primitives as main. The files are
deliberately not exported from relic_core.dart: they are an implementation
detail here, and keeping them internal leaves the 1.2.x public API surface
unchanged.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 17, 2026
DigestAuthorizationHeader.headerValue joined the scheme into the
comma-separated param list, emitting "Digest, username=...". The old
regex parser skimmed past the junk, but the linear header scanner
rightly rejects the encoder's own output, breaking codec round-trips.

Mirror the encoder fixed on main by serverpod#360 (excluded from this backport):
a single SP after the scheme (RFC 7235 2.1), quoted-string escaping
with a control-character guard for text params, and bare tokens for
algorithm, qop, and nc.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 17, 2026
dart:io owns Transfer-Encoding framing and Connection handling: on a
bodyless GET it waits for a chunked body the client never sends, on
Dart 3.13+ HttpServer rejects an empty or unknown Transfer-Encoding
coding at the protocol layer, and it drops an empty Connection request
header. Ten round-trip tests hung for 30s or saw closed connections.

Backport the test-side reshaping from serverpod#360 onto the 1.2 line: the
affected Transfer-Encoding and empty-Connection cases move to direct
unit tests in relic_core against the 1.2 parse API, keeping 1.2
semantics (chunked reordering, closed directive set). No runtime code
changes.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 17, 2026
Backported from serverpod#360 (RFC compliant typed headers) so the header-parsing
security fixes can build on the same primitives as main. The files are
deliberately not exported from relic_core.dart: they are an implementation
detail here, and keeping them internal leaves the 1.2.x public API surface
unchanged.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 17, 2026
DigestAuthorizationHeader.headerValue joined the scheme into the
comma-separated param list, emitting "Digest, username=...". The old
regex parser skimmed past the junk, but the linear header scanner
rightly rejects the encoder's own output, breaking codec round-trips.

Mirror the encoder fixed on main by serverpod#360 (excluded from this backport):
a single SP after the scheme (RFC 7235 2.1), quoted-string escaping
with a control-character guard for text params, and bare tokens for
algorithm, qop, and nc.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 18, 2026
dart:io owns Transfer-Encoding framing and Connection handling: on a
bodyless GET it waits for a chunked body the client never sends, on
Dart 3.13+ HttpServer rejects an empty or unknown Transfer-Encoding
coding at the protocol layer, and it drops an empty Connection request
header. Ten round-trip tests hung for 30s or saw closed connections.

Backport the test-side reshaping from serverpod#360 onto the 1.2 line: the
affected Transfer-Encoding and empty-Connection cases move to direct
unit tests in relic_core against the 1.2 parse API, keeping 1.2
semantics (chunked reordering, closed directive set). No runtime code
changes.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 18, 2026
Backported from serverpod#360 (RFC compliant typed headers) so the header-parsing
security fixes can build on the same primitives as main. The files are
deliberately not exported from relic_core.dart: they are an implementation
detail here, and keeping them internal leaves the 1.2.x public API surface
unchanged.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 18, 2026
DigestAuthorizationHeader.headerValue joined the scheme into the
comma-separated param list, emitting "Digest, username=...". The old
regex parser skimmed past the junk, but the linear header scanner
rightly rejects the encoder's own output, breaking codec round-trips.

Mirror the encoder fixed on main by serverpod#360 (excluded from this backport):
a single SP after the scheme (RFC 7235 2.1), quoted-string escaping
with a control-character guard for text params, and bare tokens for
algorithm, qop, and nc.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 18, 2026
DigestAuthorizationHeader.headerValue joined the scheme into the
comma-separated param list, emitting "Digest, username=...". The old
regex parser skimmed past the junk, but the linear header scanner
rightly rejects the encoder's own output, breaking codec round-trips.

Mirror the encoder fixed on main by serverpod#360 (excluded from this backport):
a single SP after the scheme (RFC 7235 2.1), quoted-string escaping
with a control-character guard for text params, and bare tokens for
algorithm, qop, and nc.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 19, 2026
DigestAuthorizationHeader.headerValue joined the scheme into the
comma-separated param list, emitting "Digest, username=...". The old
regex parser skimmed past the junk, but the linear header scanner
rightly rejects the encoder's own output, breaking codec round-trips.

Mirror the encoder fixed on main by serverpod#360 (excluded from this backport):
a single SP after the scheme (RFC 7235 2.1), quoted-string escaping
with a control-character guard for text params, and bare tokens for
algorithm, qop, and nc.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 19, 2026
DigestAuthorizationHeader.headerValue joined the scheme into the
comma-separated param list, emitting "Digest, username=...". The old
regex parser skimmed past the junk, but the linear header scanner
rightly rejects the encoder's own output, breaking codec round-trips.

Mirror the encoder fixed on main by serverpod#360 (excluded from this backport):
a single SP after the scheme (RFC 7235 2.1), quoted-string escaping
with a control-character guard for text params, and bare tokens for
algorithm, qop, and nc.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 20, 2026
Backported from serverpod#360 (RFC compliant typed headers) so the header-parsing
security fixes can build on the same primitives as main. The files are
deliberately not exported from relic_core.dart: they are an implementation
detail here, and keeping them internal leaves the 1.2.x public API surface
unchanged.
nielsenko added a commit to nielsenko/relic that referenced this pull request Aug 20, 2026
DigestAuthorizationHeader.headerValue joined the scheme into the
comma-separated param list, emitting "Digest, username=...". The old
regex parser skimmed past the junk, but the linear header scanner
rightly rejects the encoder's own output, breaking codec round-trips.

Mirror the encoder fixed on main by serverpod#360 (excluded from this backport):
a single SP after the scheme (RFC 7235 2.1), quoted-string escaping
with a control-character guard for text params, and bare tokens for
algorithm, qop, and nc.
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.

bug: SetCookieHeader emits invalid Domain (and Path) attributes via Uri.toString() Overhaul typed header parsers

2 participants