Skip to content

Markdown Feeds: Accept-header negotiation ignores quality values and only reads the first media range #1124

Description

@ekamran

Description

With the Markdown Feeds experiment and its "Serve Markdown when a request prefers it via the Accept header" setting enabled, the decision only looks at the first media range of the Accept header. Quality values are not read. On a singular URL:

Accept header What a client means Served
text/markdown;q=0.9, text/html prefers HTML Markdown
text/markdown;q=0 refuses Markdown Markdown
application/json, text/markdown accepts Markdown, not HTML HTML
text/html;q=0.1, text/markdown prefers Markdown HTML
TEXT/MARKDOWN Markdown HTML (case)

The check is preg_match( '~^text/(?:x-)?markdown(?:[,;]|$)~', $accept ) in Markdown_Feeds::is_markdown_requested().

Expected: Markdown is served when the header prefers it over HTML, as the setting's label says, and HTML in every other case. A tie, */* or text/* should keep HTML, so browsers (text/html,...,*/*;q=0.8) and curl (*/*) are not affected.

The setting is off by default and only singular URLs negotiate, so this touches few requests today. I have a fix with tests ready and will open a PR.

Step-by-step reproduction instructions

  1. Enable the Markdown Feeds experiment under Settings > AI and switch on "Serve Markdown when a request prefers it via the Accept header".
  2. Request a published post with curl -sI -H 'Accept: text/markdown;q=0.9, text/html' <post URL>. The response is text/markdown, although the header prefers HTML.
  3. Request it with curl -sI -H 'Accept: application/json, text/markdown' <post URL>. The response is text/html, although Markdown is the only acceptable type of the two.
  4. Request it with curl -sI -H 'Accept: text/markdown;q=0' <post URL>. The response is text/markdown, although the client refused it.

Screenshots, screen recording, code snippet

Output on a local site with the setting on (develop at 2cc9603):

Accept: text/markdown;q=0.9, text/html         -> text/markdown
Accept: text/markdown;q=0, text/html;q=0.5     -> text/markdown
Accept: application/json, text/markdown        -> text/html
Accept: text/html;q=0.1, text/markdown         -> text/html
Accept: TEXT/MARKDOWN ; charset=utf-8 ; q = 1  -> text/html
Accept: text/html, text/markdown               -> text/html
Accept: */*                                    -> text/html

Environment info

  • WordPress 7.1, PHP 8.5.11, SQLite (local site), pretty permalinks
  • AI plugin: develop at 2cc9603 (the Accept check is unchanged since 1.4.0)
  • Theme: Twenty Twenty-Five
  • No other plugins active

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except the AI plugin.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions