Skip to content

fix(negotiation): honor Accept exclusions and specificity before selecting a representation #10

Closed

Description

@coisa

Problem and contract

Accept::getBestMatch sorts client ranges by q and returns the first matching server type. This selects explicitly unacceptable representations and lets a wildcard override a more specific range. The documented claim of proper HTTP negotiation does not match RFC 9110 sections 12.4.2 and 12.5.1.

Evidence

Audited commit: a429fbe9a7efce6cee50b82e4a981ea7e3b47a5f.
Selection loop, parsing/sort.
Normative HTTP semantics: determine each representation's quality using its most specific matching media range; q=0 means not acceptable.

Regression cases

Run these with mb_trim available (the separate PHP compatibility issue #9 must not mask the negotiation behavior):

Accept Supported, in order Expected Current source result
application/json;q=0 JSON null JSON
application/json;q=0, /;q=1 JSON, HTML HTML JSON
text/*;q=1, text/plain;q=0.1, application/json;q=0.5 plain, JSON JSON plain
APPLICATION/JSON JSON JSON null

Acceptance criteria

  • Compute effective q per candidate from the most specific applicable range; exclude q=0 before ranking candidates.
  • Match media types and parameter names case-insensitively.
  • Add tests for these cases, including wildcard exclusions, not only equal-q positive examples.
  • Keep unsupported-type behavior returning null.

Priority P2; high confidence from branch tracing and RFC. Static validation only: no PHP executable available. Existing AcceptTest lacks these cases; all pre-existing issues/PRs were checked (#1–#8), and #9 is a separate runtime compatibility issue. No source or release changes made.

Activity

  1. coisa commented on Oct 21, 2026

    @coisa
    ContributorAuthor

    Validation update: a user-local official Debian PHP 8.4.26 CLI with mbstring became available. Executed the issue's focused cases directly against the pinned source files, without source changes or network requests. All listed current results reproduced exactly. This confirms the behavioral finding dynamically; the full PHPUnit suite has not been run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions