fix: match HTML Content-Type case-insensitively when advertising markdown twin - #90
Merged
Merged
Conversation
…down twin
HTTP media types are case-insensitive (RFC 7231 §3.1.1.1), but the cloudflare,
deno, fastly, netlify and vercel adapters gated Vary: Accept and the Link
alternate header on a case-sensitive contentType.includes("text/html"). An
upstream emitting Content-Type: Text/HTML skipped the block, dropping Vary
(risking a shared cache serving HTML to a markdown client) and the markdown
twin Link header. The check now lowercases first, matching astro, nuxt and
sveltekit which already did this. Adds a mixed-case regression test per adapter.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HTTP media types are case-insensitive (RFC 7231 §3.1.1.1), but five edge adapters gated markdown-twin advertisement on a case-sensitive
contentType.includes("text/html"). An upstream that emitsContent-Type: Text/HTML(or any non-lowercase spelling) skipped the negotiable-HTML block entirely, so the response was returned:Vary: Accept— a shared/CDN cache keyed only on URL could then serve HTML to a client that asked for markdown (or vice-versa), the exact cache-correctness bug theVaryheader exists to prevent; andLink rel="alternate"; type="text/markdown"header — so the markdown twin was never advertised to that page.The check now lowercases the header before matching, bringing these adapters in line with the astro, nuxt, and sveltekit adapters which already did
.toLowerCase().includes("text/html").This was originally raised as a Copilot review nit on #73; it's a pre-existing latent issue (not introduced by #73) and applies to five adapters, so it's fixed here as a self-contained repo-wide cleanup.
Changes
Case-insensitive HTML
Content-Typematch in:packages/cloudflare/src/worker.tspackages/deno/src/handler.tspackages/fastly/src/handler.tspackages/netlify/src/worker.tspackages/vercel/src/middleware.tsEach adapter gets a regression test asserting that an HTML response with a mixed-case
Content-Type: Text/HTML; charset=UTF-8still receives both theLinkalternate header andVary: Accept.Adds a patch changeset for the five affected packages.
Verification
tsc --noEmitclean on all five packages.text/htmlpath; this only widens the match to spec-compliant casing variants.Notes
astro/nuxt/sveltekit(already correct) ornextjs(no content-type gate).prettier --writewas intentionally not run to keep the diff surgical.Created with Squirrels