| 259 | * time. |
| 260 | */ |
| 261 | export function getCookies( |
| 262 | headers: Headers, |
| 263 | ): Partial<Record<string, string>> { |
| 264 | const cookie = headers.get("Cookie"); |
| 265 | const out: Partial<Record<string, string>> = Object.create(null); |
| 266 | if (cookie !== null) { |
| 267 | const c = cookie.split(";"); |
| 268 | for (const kv of c) { |
| 269 | const [cookieKey, ...cookieVal] = kv.split("="); |
| 270 | if (cookieKey === "") { |
| 271 | throw new SyntaxError("Cookie cannot start with '='"); |
| 272 | } |
| 273 | const key = cookieKey!.trim(); |
| 274 | out[key] = cookieVal.join("="); |
| 275 | } |
| 276 | } |
| 277 | return out; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Set the cookie header properly in the headers |