import * as frugal from "https://deno.land/x/frugal@0.9.6/dep/std/http.ts";
Provides a iterable map interfaces for managing cookies server side.
Examples
To access the keys in a request and have any set keys available for creating
a response:
To access the keys in a request and have any set keys available for creating a response:
import {
CookieMap,
mergeHeaders
} from "https://deno.land/std@0.224.0/http/cookie_map.ts";
const request = new Request("https://localhost/", {
headers: { "cookie": "foo=bar; bar=baz;"}
});
const cookies = new CookieMap(request, { secure: true });
console.log(cookies.get("foo")); // logs "bar"
cookies.set("session", "1234567", { secure: true });
const response = new Response("hello", {
headers: mergeHeaders({
"content-type": "text/plain",
}, cookies),
});
To have automatic management of cryptographically signed cookies, you can use
the SecureCookieMap
instead of CookieMap
. The biggest
difference is that the methods operate async in order to be able to support
async signing and validation of cookies:
To have automatic management of cryptographically signed cookies, you can use
the SecureCookieMap
instead of CookieMap
. The biggest
difference is that the methods operate async in order to be able to support
async signing and validation of cookies:
import {
SecureCookieMap,
mergeHeaders,
type KeyRing,
} from "https://deno.land/std@0.224.0/http/cookie_map.ts";
const request = new Request("https://localhost/", {
headers: { "cookie": "foo=bar; bar=baz;"}
});
// The keys must implement the `KeyRing` interface.
declare const keys: KeyRing;
const cookies = new SecureCookieMap(request, { keys, secure: true });
console.log(await cookies.get("foo")); // logs "bar"
// the cookie will be automatically signed using the supplied key ring.
await cookies.set("session", "1234567");
const response = new Response("hello", {
headers: mergeHeaders({
"content-type": "text/plain",
}, cookies),
});
In addition, if you have a Response
or Headers
for a
response at construction of the cookies object, they can be passed and any
set cookies will be added directly to those headers:
import { CookieMap } from "https://deno.land/std@0.224.0/http/cookie_map.ts";
const request = new Request("https://localhost/", {
headers: { "cookie": "foo=bar; bar=baz;"}
});
const response = new Response("hello", {
headers: { "content-type": "text/plain" },
});
const cookies = new CookieMap(request, { response });
console.log(cookies.get("foo")); // logs "bar"
cookies.set("session", "1234567");
Classes
Provides a way to manage cookies in a request and response on the server as a single iterable collection. | |
The base class that all derivative HTTP extend, providing a | |
Provides an way to manage cookies in a request and response on the server as a single iterable collection, as well as the ability to sign and verify cookies to prevent tampering. | |
Used to construct an HTTP server. | |
An event which contains information which will be sent to the remote
connection and be made available in an | |
An implementation of | |
Variables
Symbol which is used in mergeHeaders to extract a
| |
A namespace that contains each error constructor. Each error extends
| |
A constant array of common HTTP methods. | |
A record of all the status codes text. |
Functions
Returns an array of media types accepted by the request, in order of preference. If there are no media types supplied in the request, then any media type selector will be returned. | |
Returns an array of content encodings accepted by the request, in order of
preference. If there are no encoding supplied in the request, then | |
Returns an array of languages accepted by the request, in order of
preference. If there are no languages supplied in the request, then | |
Calculate an ETag for an entity. When the entity is a specific set of data it will be fingerprinted as a "strong" tag, otherwise if it is just file information, it will be calculated as a weak tag. | |
A factory function which provides a way to create errors. It takes up to 3
arguments, the error | |
Set the cookie header with empty value in the headers to delete it | |
Parse cookies of a header | |
Parse set-cookies of a header | |
A helper function that takes the value from the | |
A helper function that takes the value from the | |
A type guard that determines if the status code is a client error. | |
A type guard that determines if the status code is an error. | |
A type guard that determines if the value is an HttpError or not. | |
A type guard that determines if a value is a valid HTTP method. | |
A type guard that determines if the status code is informational. | |
A type guard that determines if the status code is a redirection. | |
A type guard that determines if the status code is a server error. | |
A type guard that determines if the status code is successful. | |
Allows merging of various sources of headers into a final set of headers
which can be used in a | |
Serves HTTP requests with the given handler. | |
Constructs a server, accepts incoming connections on the given listener, and handles requests on these connections with the given handler. | |
Serves HTTPS requests with the given handler. | |
Set the cookie header properly in the headers |
Interfaces
Information about the connection a request arrived on. | |
Provides a iterable map interfaces for managing cookies server side. | |
I Cpu | |
Just the part of | |
An interface which describes the methods that | |
I Os | |
Additional serve options. | |
Options for running an HTTP server. | |
Type Aliases
An HTTP status that is a client error (4XX). | |
T Data | Types of data that can be signed cryptographically. |
An HTTP status that is an error (4XX and 5XX). | |
A handler for HTTP requests. Consumes a request and connection information and returns a response. | |
A type representing string literals of each of the common HTTP method. | |
An HTTP status that is a informational (1XX). | |
An HTTP status that is a redirect (3XX). | |
An HTTP status that is a server error (5XX). | |
An HTTP status that is a success (2XX). |