Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions apps/skills/src/app/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ For the full, current flag list and any commands added after this skill was gene
const COMMON_HEADERS = {
"Cache-Control": "public, max-age=3600, s-maxage=3600",
// CDN must cache markdown (curl/agents) and HTML (browser navigate) separately.
Comment thread
mantrakp04 marked this conversation as resolved.
"Vary": "Sec-Fetch-Mode, Sec-Fetch-Dest",
"Vary": "Accept",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, HEAD, OPTIONS",
"Access-Control-Allow-Headers": "*",
Expand Down Expand Up @@ -431,12 +431,18 @@ function renderHtml(): string {
</html>`;
}

const MARKDOWN_PREFERRING_TYPES = new Set(["*/*", "text/plain", "text/markdown", "text/x-markdown"]);

function wantsHtml(req: Request): boolean {
// Browsers navigating to a top-level URL send Sec-Fetch-Mode: navigate.
// curl, fetch(), and agent fetchers do not, so they keep getting markdown.
if (req.headers.get("sec-fetch-mode") === "navigate") return true;
if (req.headers.get("sec-fetch-dest") === "document") return true;
return false;
// Browsers send `Accept: text/html,...` before `*/*`; curl/fetch/agents send
// `*/*` (or omit Accept). Serve HTML only when text/html appears AND is
// listed before any markdown-preferring type that would otherwise win.
const accept = req.headers.get("accept") ?? "";
const types = accept.split(",").map((part) => part.trim().split(";")[0].trim().toLowerCase());
const htmlIndex = types.indexOf("text/html");
if (htmlIndex === -1) return false;
const competitorIndex = types.findIndex((t) => MARKDOWN_PREFERRING_TYPES.has(t));
return competitorIndex === -1 || htmlIndex < competitorIndex;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

export function GET(req: Request) {
Expand Down
Loading