summaryrefslogtreecommitdiff
path: root/http/cookie.ts
diff options
context:
space:
mode:
authorVincent LE GOFF <g_n_s@hotmail.fr>2019-04-24 13:38:52 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-04-24 07:38:52 -0400
commite1f7a60bb326f8299f339635c0738d28431afa0a (patch)
treeddcad79b9544a325a081ec4b82a6b87b59ce1255 /http/cookie.ts
parent0fb83ba0d2e8facfa32e92a4d0700caad83701d9 (diff)
http : Add cookie module (denoland/deno_std#338)
Original: https://github.com/denoland/deno_std/commit/1d8544788648b4c571d10b9a55cc3670a1cbf69c
Diffstat (limited to 'http/cookie.ts')
-rw-r--r--http/cookie.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/http/cookie.ts b/http/cookie.ts
new file mode 100644
index 000000000..e78d48238
--- /dev/null
+++ b/http/cookie.ts
@@ -0,0 +1,21 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+import { ServerRequest } from "./server.ts";
+
+export interface Cookie {
+ [key: string]: string;
+}
+
+/* Parse the cookie of the Server Request */
+export function getCookie(rq: ServerRequest): Cookie {
+ if (rq.headers.has("Cookie")) {
+ const out: Cookie = {};
+ const c = rq.headers.get("Cookie").split(";");
+ for (const kv of c) {
+ const cookieVal = kv.split("=");
+ const key = cookieVal.shift().trim();
+ out[key] = cookieVal.join("");
+ }
+ return out;
+ }
+ return {};
+}