mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-26 05:23:34 +00:00
fix(stats): include locale header in vary (#34789)
This commit is contained in:
parent
beb586a383
commit
fc29f99190
3 changed files with 16 additions and 5 deletions
|
|
@ -39,7 +39,7 @@ export async function statsProxy(evt: APIEvent) {
|
|||
headers.delete("content-encoding")
|
||||
headers.delete("content-length")
|
||||
headers.delete("etag")
|
||||
appendVary(headers, "Accept-Language", "Cookie")
|
||||
appendVary(headers, "Accept-Language", "Cookie", LOCALE_HEADER)
|
||||
|
||||
return new Response(rewriteStatsHtml(await response.text()), {
|
||||
status: response.status,
|
||||
|
|
@ -78,7 +78,7 @@ function redirectToLocalizedData(request: Request, url: URL, locale: ReturnType<
|
|||
Location: next.toString(),
|
||||
})
|
||||
headers.append("set-cookie", cookie(locale))
|
||||
appendVary(headers, "Accept-Language", "Cookie")
|
||||
appendVary(headers, "Accept-Language", "Cookie", LOCALE_HEADER)
|
||||
|
||||
return new Response(null, {
|
||||
status: 308,
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ import { createStore } from "solid-js/store"
|
|||
import { createSimpleContext } from "@opencode-ai/ui/context"
|
||||
import {
|
||||
LOCALES,
|
||||
cookie,
|
||||
detectFromLanguages,
|
||||
dir,
|
||||
fromPathname,
|
||||
label,
|
||||
localeFromCookieHeader,
|
||||
localeFromRequest,
|
||||
|
|
@ -19,11 +21,16 @@ function initial() {
|
|||
const event = getRequestEvent()
|
||||
if (event) return localeFromRequest(event.request)
|
||||
|
||||
if (typeof window === "object") {
|
||||
const fromPath = fromPathname(window.location.pathname)
|
||||
if (fromPath) return fromPath
|
||||
}
|
||||
|
||||
if (typeof document === "object") {
|
||||
const fromDom = parseLocale(document.documentElement.dataset.locale)
|
||||
if (fromDom) return fromDom
|
||||
const fromCookie = localeFromCookieHeader(document.cookie)
|
||||
if (fromCookie) return fromCookie
|
||||
const fromDom = parseLocale(document.documentElement.dataset.locale)
|
||||
if (fromDom) return fromDom
|
||||
}
|
||||
|
||||
if (typeof navigator !== "object") return "en" satisfies Locale
|
||||
|
|
@ -55,6 +62,8 @@ export const { use: useLanguage, provider: LanguageProvider } = createSimpleCont
|
|||
},
|
||||
setLocale(next: Locale) {
|
||||
setStore("locale", next)
|
||||
if (typeof document !== "object") return
|
||||
document.cookie = cookie(next)
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import { LOCALE_HEADER } from "../lib/language"
|
||||
|
||||
const statsPageCacheControl = "public, max-age=60, s-maxage=300, stale-while-revalidate=86400"
|
||||
|
||||
export function setStatsPageCacheHeaders(headers: Headers | undefined) {
|
||||
if (!headers) return
|
||||
|
||||
headers.set("Cache-Control", statsPageCacheControl)
|
||||
appendVary(headers, "Accept-Language", "Cookie")
|
||||
appendVary(headers, "Accept-Language", "Cookie", LOCALE_HEADER)
|
||||
}
|
||||
|
||||
function appendVary(headers: Headers, ...values: string[]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue