Skip to content

[codex] fix markdown accept negotiation#142

Merged
basit3407 merged 3 commits intomainfrom
codex/fix-markdown-accept-negotiation
Apr 22, 2026
Merged

[codex] fix markdown accept negotiation#142
basit3407 merged 3 commits intomainfrom
codex/fix-markdown-accept-negotiation

Conversation

@basit3407
Copy link
Copy Markdown
Collaborator

What changed

  • replaced the boolean markdown check with proper Accept negotiation between text/html and text/markdown
  • honor q values and q=0 when ranking supported representations
  • return 406 Not Acceptable only when the client rejects both HTML and Markdown
  • added regression tests for HTML-preferred requests and unsupported-only Accept headers

Why this changed

The docs site was scoring 75/100 on acceptmarkdown.com because it always served Markdown whenever text/markdown appeared anywhere in the Accept header, even when HTML had a higher preference, and it silently fell back to HTML for unsupported types instead of returning 406.

Impact

  • browsers and general clients still default to HTML
  • agent clients that explicitly prefer Markdown still receive Markdown
  • restrictive unsupported Accept headers now get a standards-correct 406 response instead of a silent HTML fallback

Root cause

The edge middleware only answered ?does this request mention text/markdown with q > 0?? rather than performing best-match content negotiation across the representations the site can actually serve.

Validation

  • NODE_PATH=C:\Code\qf-api-docs\node_modules C:\Users\Basit\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe --test tests\markdown-negotiation.test.cjs
  • NODE_PATH=C:\Code\qf-api-docs\node_modules C:\Users\Basit\.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe --test tests\*.test.cjs
@basit3407 basit3407 marked this pull request as ready for review April 22, 2026 03:21
@basit3407 basit3407 requested a review from Copilot April 22, 2026 03:21
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 22, 2026

Deploying qf-api-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: debf726
Status: ✅  Deploy successful!
Preview URL: https://6521ef7a.qf-api-docs.pages.dev
Branch Preview URL: https://codex-fix-markdown-accept-ne.qf-api-docs.pages.dev

View logs

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the docs edge middleware to perform standards-based Accept content negotiation between HTML and Markdown, ensuring clients receive the best supported representation (or a correct 406 Not Acceptable when none are acceptable).

Changes:

  • Replace the previous “mentions text/markdown” boolean check with ranked negotiation honoring q values and wildcards.
  • Add a 406 Not Acceptable response path when both HTML and Markdown are rejected.
  • Add regression tests covering ranking behavior, HTML-preferred requests, and unsupported-only Accept headers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/markdown-negotiation-shared.cjs Adds parsing + ranking helpers for Accept negotiation across supported media types.
src/markdown-negotiation-runtime.cjs Uses ranked negotiation to choose HTML vs Markdown, and returns 406 when neither is acceptable.
tests/markdown-negotiation.test.cjs Adds regression tests for ranking, HTML preference via q, and 406 behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/markdown-negotiation-runtime.cjs
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e5ecd23c55

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/markdown-negotiation-runtime.cjs Outdated
Comment thread src/markdown-negotiation-runtime.cjs
@basit3407
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@basit3407 basit3407 merged commit b2d55e6 into main Apr 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants