MCPcopy Index your code
hub / github.com/anomalyco/opencode / redirectToLocalizedData

Function redirectToLocalizedData

packages/console/app/src/lib/stats-proxy.ts:66–87  ·  view source on GitHub ↗
(request: Request, url: URL, locale: ReturnType<typeof localeFromRequest>)

Source from the content-addressed store, hash-verified

64}
65
66function redirectToLocalizedData(request: Request, url: URL, locale: ReturnType<typeof localeFromRequest>) {
67 if (locale === "en") return null
68 if (request.headers.get(LOCALE_HEADER)) return null
69 if (request.method !== "GET" && request.method !== "HEAD") return null
70 if (!acceptsHtml(request)) return null
71 if (!url.pathname.startsWith(`${dataPath}/`) && url.pathname !== dataPath) return null
72 if (isDataBypassPath(url.pathname)) return null
73
74 const next = new URL(url)
75 next.pathname = route(locale, url.pathname)
76
77 const headers = new Headers({
78 Location: next.toString(),
79 })
80 headers.append("set-cookie", cookie(locale))
81 appendVary(headers, "Accept-Language", "Cookie")
82
83 return new Response(null, {
84 status: 308,
85 headers,
86 })
87}
88
89function acceptsHtml(request: Request) {
90 const accept = request.headers.get("accept")

Callers 1

statsProxyFunction · 0.85

Calls 7

routeFunction · 0.90
cookieFunction · 0.90
acceptsHtmlFunction · 0.85
isDataBypassPathFunction · 0.85
appendVaryFunction · 0.70
getMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected