import { Cookies } from "https://dotland-vbqsvsrpfncg.deno-staging.dev/x/oak@v11.1.0/cookies.ts?p=prototype.%5BSymbol.asyncIterator%5D&s=Cookies";
An interface which allows setting and accessing cookies related to both the
current request and response. Each {@link Context
} has a property
.cookies
which is an instance of this class.
Because oak supports automatic encryption, most methods (except .delete
)
are asynchronous. This is because oak leverages the Web Crypto APIs, which
are asynchronous by nature.
Example
import { Application } from "https://deno.land/x/oak/mod.ts";
const app = new Application();
app.use(async (ctx) => {
for await (const cookie of ctx.cookies) {
// iterating over each cookie
}
await ctx.cookie.set("myCookie", "a value"); // setting or updating a cookie
const id = await ctx.cookie.get("my-id"); // getting a value of a cookie if present
ctx.cookie.delete();
});
Constructors
Methods
Set a cookie to be deleted in the response. This is a "shortcut" to
.set(name, null, options?)
.
Iterate over the request's cookies, yielding up a tuple containing the key and the value.
If there are keys set on the application, only keys and values that are properly signed will be returned.
Get the value of a cookie from the request.
If the cookie is signed, and the signature is invalid, the cookie will be set to be deleted in the the response. If the signature uses an "old" key, the cookie will be re-signed with the current key and be added to the response to be updated.
Iterate over the request's cookies, yielding up the keys.
If there are keys set on the application, only the keys that are properly signed will be returned.
Set a cookie in the response.
If there are keys set in the application, cookies will be automatically
signed, unless overridden by the set options. Cookies can be deleted by
setting the value to null
.
Iterate over the request's cookies, yielding up each value.
If there are keys set on the application, only the values that are properly signed will be returned.
Iterate over the request's cookies, yielding up a tuple containing the key and the value.
If there are keys set on the application, only keys and values that are properly signed will be returned.