Skip to content

Commit

Permalink
feat(http): Allow passing path and domain attributes while removing c…
Browse files Browse the repository at this point in the history
…ookies (#1005)
  • Loading branch information
getspooky authored Jul 6, 2021
1 parent 416ef01 commit d8e61e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion http/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,18 @@ export function setCookie(res: { headers?: Headers }, cookie: Cookie): void {
* Example:
*
* deleteCookie(res,'foo');
* deleteCookie(res,'foo', {path:'/demo'});
* deleteCookie(res,'foo', {domain:'deno.land'});
*/
export function deleteCookie(res: { headers?: Headers }, name: string): void {
export function deleteCookie(
res: { headers?: Headers },
name: string,
attributes?: { path?: string; domain?: string },
): void {
setCookie(res, {
name: name,
value: "",
expires: new Date(0),
...attributes,
});
}
12 changes: 12 additions & 0 deletions http/cookie_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ Deno.test({
res.headers?.get("Set-Cookie"),
"deno=; Expires=Thu, 01 Jan 1970 00:00:00 GMT",
);
res.headers = new Headers();
setCookie(res, {
name: "Space",
value: "Cat",
domain: "deno.land",
path: "/",
});
deleteCookie(res, "Space", { domain: "", path: "" });
assertEquals(
res.headers?.get("Set-Cookie"),
"Space=Cat; Domain=deno.land; Path=/, Space=; Expires=Thu, 01 Jan 1970 00:00:00 GMT",
);
},
});

Expand Down

0 comments on commit d8e61e4

Please sign in to comment.