|
1 | 1 | import { Buffer } from "node:buffer"; |
2 | 2 |
|
3 | | -import { parseCookies } from "http/util"; |
| 3 | +import cookieParser from "cookie"; |
| 4 | +import { parseSetCookieHeader } from "http/util"; |
4 | 5 | import type { |
5 | 6 | InternalEvent, |
6 | 7 | InternalResult, |
@@ -29,11 +30,11 @@ const converter: Converter<InternalEvent, InternalResult | MiddlewareResult> = { |
29 | 30 | const rawPath = url.pathname; |
30 | 31 | const method = event.method; |
31 | 32 | const shouldHaveBody = method !== "GET" && method !== "HEAD"; |
32 | | - const cookies: Record<string, string> = Object.fromEntries( |
33 | | - parseCookies(event.headers.get("cookie")).map((cookie) => |
34 | | - cookie.split("="), |
35 | | - ), |
36 | | - ); |
| 33 | + |
| 34 | + const cookieHeader = event.headers.get("cookie"); |
| 35 | + const cookies = cookieHeader |
| 36 | + ? (cookieParser.parse(cookieHeader) as Record<string, string>) |
| 37 | + : {}; |
37 | 38 |
|
38 | 39 | return { |
39 | 40 | type: "core", |
@@ -81,7 +82,7 @@ const converter: Converter<InternalEvent, InternalResult | MiddlewareResult> = { |
81 | 82 | if (key === "set-cookie" && typeof value === "string") { |
82 | 83 | // If the value is a string, we need to parse it into an array |
83 | 84 | // This is the case for middleware direct result |
84 | | - const cookies = parseCookies(value); |
| 85 | + const cookies = parseSetCookieHeader(value); |
85 | 86 | for (const cookie of cookies) { |
86 | 87 | headers.append(key, cookie); |
87 | 88 | } |
|
0 commit comments