diff options
| author | Vincent LE GOFF <g_n_s@hotmail.fr> | 2019-04-28 01:07:11 +0200 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-04-27 16:07:11 -0700 |
| commit | ce101a0f8632f6b5390af247f3df2002e86becdf (patch) | |
| tree | 5232eb3cbd21c8773881327f98162f0567dfe543 /http/README.md | |
| parent | 8d49022ef67b590d8ee7b3ff984307b6c0a69d4f (diff) | |
http: Cookie improvements (denoland/deno_std#359)
Original: https://github.com/denoland/deno_std/commit/f1114691038888fc3d8995b64a8028f072569672
Diffstat (limited to 'http/README.md')
| -rw-r--r-- | http/README.md | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/http/README.md b/http/README.md index 448692a68..c7bac3f09 100644 --- a/http/README.md +++ b/http/README.md @@ -2,6 +2,45 @@ A framework for creating HTTP/HTTPS server. +## Cookie + +Helper to manipulate `Cookie` throught `ServerRequest` and `Response`. + +```ts +import { getCookies } from "https://deno.land/std/http/cookie.ts"; + +let req = new ServerRequest(); +req.headers = new Headers(); +req.headers.set("Cookie", "full=of; tasty=chocolate"); + +const c = getCookies(request); +// c = { full: "of", tasty: "chocolate" } +``` + +To set a `Cookie` you can add `CookieOptions` to properly set your `Cookie` + +```ts +import { setCookie } from "https://deno.land/std/http/cookie.ts"; + +let res: Response = {}; +res.headers = new Headers(); +setCookie(res, { name: "Space", value: "Cat" }); +``` + +Deleting a `Cookie` will set its expiration date before now. +Forcing the browser to delete it. + +```ts +import { delCookie } from "https://deno.land/std/http/cookie.ts"; + +let res = new Response(); +delCookie(res, "deno"); +// Will append this header in the response +// "Set-Cookie: deno=; Expires=Thus, 01 Jan 1970 00:00:00 GMT" +``` + +**Note**: At the moment multiple `Set-Cookie` in a `Response` is not handled. + ## Example ```typescript |
