Skip to content

ledger: negotiate Accept in-tree - #278

Merged
rvolosatovs merged 1 commit into
mainfrom
roman/ledger/accept
Oct 21, 2026
Merged

rvolosatovs merged 1 commit into
mainfrom
roman/ledger/accept

Conversation

@rvolosatovs

@rvolosatovs rvolosatovs commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Last commit in https://github.com/maxcountryman/headers-accept repo is 8 months old and the crate is not spec-compliant at the moment. The functionality we need is really simple, so just implement it in-tree and drop the dependency

Base automatically changed from roman/ledger/utxo-wit to main October 21, 2026 15:28
@rvolosatovs
rvolosatovs force-pushed the roman/ledger/accept branch 5 times, most recently from 87e199e to e73f3b2 Compare October 21, 2026 16:08
Replace the `headers-accept` dependency, pinned to an unmerged upstream
PR for its `q`-insensitive parameter matching, with a small RFC 9110
section 12.5.1 implementation. `headers-core` is dropped along with it.

Media ranges are parsed directly from the field bytes following the
RFC 9110 grammar: HTTP tokens, empty list elements and parameters,
quoted-string values with quoted-pairs and `obs-text`, and no
whitespace around `=`. Only exact `*` subtypes are wildcards, so
`*/*+json` and `*/wasm` are literal ranges that match nothing. Type,
subtype and parameter names compare case-insensitively, quoted and
token parameter values are equivalent, and `charset` values compare
case-insensitively. Any parameter named `q` is the weight regardless
of its position, and a range with more than one weight is rejected.

The most specific media range matching an available type determines
its quality, ranges with `q=0` exclude it. Ties are broken by
specificity, header order and server preference. Negotiation now
always yields a media type, defaulting to the first available one
without an `Accept` header, which simplifies the handlers. An `Accept`
header listing no media ranges, such as an empty one, is treated as
absent, as Spring, ASP.NET Core and Gin do, instead of rejecting every
representation with 406.

`AcceptHeaderError::Decoding` is replaced by `Malformed`, `Quality`
and `QualityDuplicate`.

Unit tests in the `accept` module cover the negotiation.

Assisted-by: anthropic:claude-opus-5-5
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs
rvolosatovs marked this pull request as ready for review October 21, 2026 17:35

@SpaceManiac SpaceManiac 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.

Seems OK

@rvolosatovs
rvolosatovs merged commit cf918d9 into main Oct 21, 2026
5 checks passed
@rvolosatovs
rvolosatovs deleted the roman/ledger/accept branch October 21, 2026 23:12
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.

2 participants