Skip to content

Parse spaces and parameters of the Accept header in ErrorHandler - #3495

Open
Asimmirzac wants to merge 1 commit into
slimphp:4.xfrom
Asimmirzac:error-handler-accept
Open

Asimmirzac wants to merge 1 commit into
slimphp:4.xfrom
Asimmirzac:error-handler-accept

Conversation

@Asimmirzac

Copy link
Copy Markdown

ErrorHandler::determineContentType() splits the Accept header at the commas and compares the parts as they are. Media types after a space or with a parameter are never found:

Accept before after
application/unknown, application/json default (HTML) application/json
text/plain, application/json text/plain application/json (as for text/plain,application/json)
application/json;q=0.9 default (HTML) application/json
application/json; charset=utf-8 default (HTML) application/json
application/json;q=0, text/xml default (HTML) text/xml

The parts are now trimmed, the parameters are removed, and the types are ordered by their quality value, so text/html;q=0.8, application/json still gives JSON. Types with q=0 are skipped. Headers without spaces and parameters give the same result as before, and so does the +json/+xml fallback.

All tests pass on PHP 8.3 (run without coverage), phpcs and phpstan are clean, and seven of the nine new data sets fail without the change.

Prepared with AI assistance.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 99.461% (+0.005%) from 99.456% — Asimmimx:error-handler-accept into slimphp:4.x

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