MCPcopy Create free account
hub / github.com/denoland/std / getCookies

Function getCookies

http/cookie.ts:261–278  ·  view source on GitHub ↗
(
  headers: Headers,
)

Source from the content-addressed store, hash-verified

259 * time.
260 */
261export 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

Callers 1

fnFunction · 0.90

Calls 1

getMethod · 0.65

Tested by

no test coverage detected