Repository navigation
perf(webapp): run the proxy only on post requests it acts on - #7556
Merged
Merged
Conversation
The proxy matched every /posts/* request, but it only changes the response for markdown requests (Accept header or .md suffix) and for laptop-mirror document requests (dl_v=v2 cookie). Over 12h that was ~367K no-op invocations vs ~50K rewrites, each billed as a function invocation in front of the CDN cache. Gate the post matcher on those conditions with has/missing so plain post requests go straight to the cached page. The q-value logic stays in acceptsMarkdown; the matcher only pre-filters on the media type appearing in Accept (lowercase, as every agent we see sends it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FodmVu2j66685xSYXwxrdd
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Requested by Ido · project thread
Changes
proxy.ts) matched every/posts/*request, but it changes the response only for:Acceptheader namingtext/markdownortext/x-markdown, or the.mdsuffix)dl_v=v2cookie, not a_next/datarequest)NextResponse.next(), against about 50K that rewrote. Vercel bills each one as a function invocation, and it runs in front of the CDN cache, so even cache hits paid for it./posts/:path*matcher now useshas/missingconditions, so plain post requests skip the proxy and go straight to the cached page./api/md/*and the.mdpages stay unconditional.acceptsMarkdownstill makes the final decision, including the q-value comparison withtext/html. The matcher only pre-filters on the media type appearing inAccept.Tradeoffs:
text/markdown). A client sendingText/Markdownwould now get HTML instead of markdown. Every agent we see sends lowercase.Events
No
Experiment
No
Manual Testing
Checked on the preview deployment:
Accept: text/markdownon/posts/<slug>returns markdown (proxy rewrite to/api/md/posts/[id])Accept: text/html, text/markdown;q=0.5returns HTML (proxy runs,acceptsMarkdowndeclines)/posts/<id>.mdreturns markdowndl_v=v2returnsx-layout-variant: v2from/layout-v2/posts/[id]dl_v=v1, HTML Accept, 11 requests) return HTML and log no middleware invocation; only the 4 requests above appear in the deployment's middleware metricshttps://claude.ai/code/session_01FodmVu2j66685xSYXwxrdd
Generated by Claude Code