Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(http): Allow Passing the exact same path and domain attributes while removing cookies #1005

Merged
merged 4 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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