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 2 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
7 changes: 6 additions & 1 deletion http/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,15 @@ export function setCookie(res: { headers?: Headers }, cookie: Cookie): void {
*
* deleteCookie(res,'foo');
*/
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,
});
}
19 changes: 19 additions & 0 deletions http/cookie_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { Response, ServerRequest } from "./server.ts";
import { deleteCookie, getCookies, setCookie } from "./cookie.ts";
import { assert, assertEquals, assertThrows } from "../testing/asserts.ts";

Deno.test({
name: "Cookie response",
fn(): void {
//
},
});

getspooky marked this conversation as resolved.
Show resolved Hide resolved
Deno.test({
name: "Cookie parser",
fn(): void {
Expand Down Expand Up @@ -135,6 +142,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