(request: Request, url: URL, locale: ReturnType<typeof localeFromRequest>)
| 64 | } |
| 65 | |
| 66 | function 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 | |
| 89 | function acceptsHtml(request: Request) { |
| 90 | const accept = request.headers.get("accept") |
no test coverage detected