@netlify/plugin-nextjs 4.40.1 → 4.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers/edge.js +1 -0
- package/lib/templates/vendor.js +20 -0
- package/package.json +7 -4
- package/src/templates/edge/next-dev.js +3 -3
- package/src/templates/edge/shims.js +6 -6
- package/src/templates/edge-shared/next-utils.ts +3 -3
- package/src/templates/edge-shared/utils.ts +1 -1
- package/src/templates/vendor/deno.land/std@0.134.0/fmt/colors.ts +536 -0
- package/src/templates/vendor/deno.land/std@0.134.0/testing/_diff.ts +360 -0
- package/src/templates/vendor/deno.land/std@0.134.0/testing/asserts.ts +866 -0
- package/src/templates/vendor/deno.land/std@0.175.0/_util/asserts.ts +25 -0
- package/src/templates/vendor/deno.land/std@0.175.0/_util/os.ts +23 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/abortable.ts +149 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/deadline.ts +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/debounce.ts +79 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/deferred.ts +48 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/delay.ts +67 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/mod.ts +18 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +97 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/pool.ts +95 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/retry.ts +81 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/tee.ts +100 -0
- package/src/templates/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +49 -0
- package/src/templates/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +29 -0
- package/src/templates/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +45 -0
- package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64.ts +144 -0
- package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64url.ts +70 -0
- package/src/templates/vendor/deno.land/std@0.175.0/flags/mod.ts +785 -0
- package/src/templates/vendor/deno.land/std@0.175.0/fmt/colors.ts +569 -0
- package/src/templates/vendor/deno.land/std@0.175.0/fmt/printf.ts +939 -0
- package/src/templates/vendor/deno.land/std@0.175.0/http/cookie.ts +403 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_core.ts +77 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_events.d.ts +848 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_events.mjs +1033 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_global.d.ts +66 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_next_tick.ts +173 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +4 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/process.ts +131 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +146 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.d.ts +1488 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.mjs +746 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +129 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_utils.ts +206 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/assert.ts +940 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/assertion_error.ts +579 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/async_hooks.ts +331 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/buffer.ts +13 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/events.ts +14 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +2074 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +2607 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +5 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/errors.ts +2867 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +123 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/net.ts +95 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +72 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/options.ts +45 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +272 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +137 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +580 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +320 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +229 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +242 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +669 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +118 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +2237 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +113 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util.mjs +143 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +317 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +229 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +18 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +12 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +86 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +16873 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +66 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +152 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +130 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +541 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +80 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +900 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +14 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +50 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +108 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +84 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +39 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +392 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +354 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +15 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +27 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +488 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +186 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +496 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +126 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +437 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/process.ts +705 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/stream.ts +37 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/string_decoder.ts +337 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/util/types.ts +4 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/util.ts +289 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_constants.ts +49 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_interface.ts +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_util.ts +194 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/common.ts +40 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/glob.ts +418 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/mod.ts +53 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/posix.ts +487 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/separator.ts +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/win32.ts +962 -0
- package/src/templates/vendor/deno.land/std@0.175.0/streams/write_all.ts +64 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/_diff.ts +440 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/_format.ts +23 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/asserts.ts +906 -0
- package/src/templates/vendor/deno.land/std@0.175.0/types.d.ts +89 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +133 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +112 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +88 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +974 -0
- package/src/templates/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +621 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +13 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +12 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +5 -0
- package/src/templates/vendor/import_map.json +13 -0
- package/src/templates/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +50 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// Structured similarly to Go's cookie.go
|
|
3
|
+
// https://github.com/golang/go/blob/master/src/net/http/cookie.go
|
|
4
|
+
// This module is browser compatible.
|
|
5
|
+
|
|
6
|
+
import { assert } from "../_util/asserts.ts";
|
|
7
|
+
import { toIMF } from "../datetime/to_imf.ts";
|
|
8
|
+
|
|
9
|
+
export interface Cookie {
|
|
10
|
+
/** Name of the cookie. */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Value of the cookie. */
|
|
13
|
+
value: string;
|
|
14
|
+
/** The cookie's `Expires` attribute, either as an explicit date or UTC milliseconds.
|
|
15
|
+
* @example <caption>Explicit date:</caption>
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { Cookie } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";
|
|
19
|
+
* const cookie: Cookie = {
|
|
20
|
+
* name: 'name',
|
|
21
|
+
* value: 'value',
|
|
22
|
+
* // expires on Fri Dec 30 2022
|
|
23
|
+
* expires: new Date('2022-12-31')
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example <caption>UTC milliseconds</caption>
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { Cookie } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";
|
|
31
|
+
* const cookie: Cookie = {
|
|
32
|
+
* name: 'name',
|
|
33
|
+
* value: 'value',
|
|
34
|
+
* // expires 10 seconds from now
|
|
35
|
+
* expires: Date.now() + 10000
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
expires?: Date | number;
|
|
40
|
+
/** The cookie's `Max-Age` attribute, in seconds. Must be a non-negative integer. A cookie with a `maxAge` of `0` expires immediately. */
|
|
41
|
+
maxAge?: number;
|
|
42
|
+
/** The cookie's `Domain` attribute. Specifies those hosts to which the cookie will be sent. */
|
|
43
|
+
domain?: string;
|
|
44
|
+
/** The cookie's `Path` attribute. A cookie with a path will only be included in the `Cookie` request header if the requested URL matches that path. */
|
|
45
|
+
path?: string;
|
|
46
|
+
/** The cookie's `Secure` attribute. If `true`, the cookie will only be included in the `Cookie` request header if the connection uses SSL and HTTPS. */
|
|
47
|
+
secure?: boolean;
|
|
48
|
+
/** The cookie's `HTTPOnly` attribute. If `true`, the cookie cannot be accessed via JavaScript. */
|
|
49
|
+
httpOnly?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Allows servers to assert that a cookie ought not to
|
|
52
|
+
* be sent along with cross-site requests.
|
|
53
|
+
*/
|
|
54
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
55
|
+
/** Additional key value pairs with the form "key=value" */
|
|
56
|
+
unparsed?: string[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const FIELD_CONTENT_REGEXP = /^(?=[\x20-\x7E]*$)[^()@<>,;:\\"\[\]?={}\s]+$/;
|
|
60
|
+
|
|
61
|
+
function toString(cookie: Cookie): string {
|
|
62
|
+
if (!cookie.name) {
|
|
63
|
+
return "";
|
|
64
|
+
}
|
|
65
|
+
const out: string[] = [];
|
|
66
|
+
validateName(cookie.name);
|
|
67
|
+
validateValue(cookie.name, cookie.value);
|
|
68
|
+
out.push(`${cookie.name}=${cookie.value}`);
|
|
69
|
+
|
|
70
|
+
// Fallback for invalid Set-Cookie
|
|
71
|
+
// ref: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-prefixes-00#section-3.1
|
|
72
|
+
if (cookie.name.startsWith("__Secure")) {
|
|
73
|
+
cookie.secure = true;
|
|
74
|
+
}
|
|
75
|
+
if (cookie.name.startsWith("__Host")) {
|
|
76
|
+
cookie.path = "/";
|
|
77
|
+
cookie.secure = true;
|
|
78
|
+
delete cookie.domain;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (cookie.secure) {
|
|
82
|
+
out.push("Secure");
|
|
83
|
+
}
|
|
84
|
+
if (cookie.httpOnly) {
|
|
85
|
+
out.push("HttpOnly");
|
|
86
|
+
}
|
|
87
|
+
if (typeof cookie.maxAge === "number" && Number.isInteger(cookie.maxAge)) {
|
|
88
|
+
assert(
|
|
89
|
+
cookie.maxAge >= 0,
|
|
90
|
+
"Max-Age must be an integer superior or equal to 0",
|
|
91
|
+
);
|
|
92
|
+
out.push(`Max-Age=${cookie.maxAge}`);
|
|
93
|
+
}
|
|
94
|
+
if (cookie.domain) {
|
|
95
|
+
validateDomain(cookie.domain);
|
|
96
|
+
out.push(`Domain=${cookie.domain}`);
|
|
97
|
+
}
|
|
98
|
+
if (cookie.sameSite) {
|
|
99
|
+
out.push(`SameSite=${cookie.sameSite}`);
|
|
100
|
+
}
|
|
101
|
+
if (cookie.path) {
|
|
102
|
+
validatePath(cookie.path);
|
|
103
|
+
out.push(`Path=${cookie.path}`);
|
|
104
|
+
}
|
|
105
|
+
if (cookie.expires) {
|
|
106
|
+
const { expires } = cookie;
|
|
107
|
+
const dateString = toIMF(
|
|
108
|
+
typeof expires === "number" ? new Date(expires) : expires,
|
|
109
|
+
);
|
|
110
|
+
out.push(`Expires=${dateString}`);
|
|
111
|
+
}
|
|
112
|
+
if (cookie.unparsed) {
|
|
113
|
+
out.push(cookie.unparsed.join("; "));
|
|
114
|
+
}
|
|
115
|
+
return out.join("; ");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Validate Cookie Name.
|
|
120
|
+
* @param name Cookie name.
|
|
121
|
+
*/
|
|
122
|
+
function validateName(name: string | undefined | null) {
|
|
123
|
+
if (name && !FIELD_CONTENT_REGEXP.test(name)) {
|
|
124
|
+
throw new TypeError(`Invalid cookie name: "${name}".`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Validate Path Value.
|
|
130
|
+
* See {@link https://tools.ietf.org/html/rfc6265#section-4.1.2.4}.
|
|
131
|
+
* @param path Path value.
|
|
132
|
+
*/
|
|
133
|
+
function validatePath(path: string | null) {
|
|
134
|
+
if (path == null) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
for (let i = 0; i < path.length; i++) {
|
|
138
|
+
const c = path.charAt(i);
|
|
139
|
+
if (
|
|
140
|
+
c < String.fromCharCode(0x20) || c > String.fromCharCode(0x7E) || c == ";"
|
|
141
|
+
) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
path + ": Invalid cookie path char '" + c + "'",
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Validate Cookie Value.
|
|
151
|
+
* See {@link https://tools.ietf.org/html/rfc6265#section-4.1}.
|
|
152
|
+
* @param value Cookie value.
|
|
153
|
+
*/
|
|
154
|
+
function validateValue(name: string, value: string | null) {
|
|
155
|
+
if (value == null || name == null) return;
|
|
156
|
+
for (let i = 0; i < value.length; i++) {
|
|
157
|
+
const c = value.charAt(i);
|
|
158
|
+
if (
|
|
159
|
+
c < String.fromCharCode(0x21) || c == String.fromCharCode(0x22) ||
|
|
160
|
+
c == String.fromCharCode(0x2c) || c == String.fromCharCode(0x3b) ||
|
|
161
|
+
c == String.fromCharCode(0x5c) || c == String.fromCharCode(0x7f)
|
|
162
|
+
) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
"RFC2616 cookie '" + name + "' cannot contain character '" + c + "'",
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
if (c > String.fromCharCode(0x80)) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
"RFC2616 cookie '" + name + "' can only have US-ASCII chars as value" +
|
|
170
|
+
c.charCodeAt(0).toString(16),
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Validate Cookie Domain.
|
|
178
|
+
* See {@link https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.2.3}.
|
|
179
|
+
* @param domain Cookie domain.
|
|
180
|
+
*/
|
|
181
|
+
function validateDomain(domain: string) {
|
|
182
|
+
if (domain == null) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const char1 = domain.charAt(0);
|
|
186
|
+
const charN = domain.charAt(domain.length - 1);
|
|
187
|
+
if (char1 == "-" || charN == "." || charN == "-") {
|
|
188
|
+
throw new Error(
|
|
189
|
+
"Invalid first/last char in cookie domain: " + domain,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Parse cookies of a header
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* import { getCookies } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";
|
|
200
|
+
*
|
|
201
|
+
* const headers = new Headers();
|
|
202
|
+
* headers.set("Cookie", "full=of; tasty=chocolate");
|
|
203
|
+
*
|
|
204
|
+
* const cookies = getCookies(headers);
|
|
205
|
+
* console.log(cookies); // { full: "of", tasty: "chocolate" }
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @param headers The headers instance to get cookies from
|
|
209
|
+
* @return Object with cookie names as keys
|
|
210
|
+
*/
|
|
211
|
+
export function getCookies(headers: Headers): Record<string, string> {
|
|
212
|
+
const cookie = headers.get("Cookie");
|
|
213
|
+
if (cookie != null) {
|
|
214
|
+
const out: Record<string, string> = {};
|
|
215
|
+
const c = cookie.split(";");
|
|
216
|
+
for (const kv of c) {
|
|
217
|
+
const [cookieKey, ...cookieVal] = kv.split("=");
|
|
218
|
+
assert(cookieKey != null);
|
|
219
|
+
const key = cookieKey.trim();
|
|
220
|
+
out[key] = cookieVal.join("=");
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
return {};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Set the cookie header properly in the headers
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* import {
|
|
233
|
+
* Cookie,
|
|
234
|
+
* setCookie,
|
|
235
|
+
* } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";
|
|
236
|
+
*
|
|
237
|
+
* const headers = new Headers();
|
|
238
|
+
* const cookie: Cookie = { name: "Space", value: "Cat" };
|
|
239
|
+
* setCookie(headers, cookie);
|
|
240
|
+
*
|
|
241
|
+
* const cookieHeader = headers.get("set-cookie");
|
|
242
|
+
* console.log(cookieHeader); // Space=Cat
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @param headers The headers instance to set the cookie to
|
|
246
|
+
* @param cookie Cookie to set
|
|
247
|
+
*/
|
|
248
|
+
export function setCookie(headers: Headers, cookie: Cookie) {
|
|
249
|
+
// Parsing cookie headers to make consistent set-cookie header
|
|
250
|
+
// ref: https://tools.ietf.org/html/rfc6265#section-4.1.1
|
|
251
|
+
const v = toString(cookie);
|
|
252
|
+
if (v) {
|
|
253
|
+
headers.append("Set-Cookie", v);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Set the cookie header with empty value in the headers to delete it
|
|
259
|
+
*
|
|
260
|
+
* > Note: Deleting a `Cookie` will set its expiration date before now. Forcing
|
|
261
|
+
* > the browser to delete it.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* import { deleteCookie } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";
|
|
266
|
+
*
|
|
267
|
+
* const headers = new Headers();
|
|
268
|
+
* deleteCookie(headers, "deno");
|
|
269
|
+
*
|
|
270
|
+
* const cookieHeader = headers.get("set-cookie");
|
|
271
|
+
* console.log(cookieHeader); // deno=; Expires=Thus, 01 Jan 1970 00:00:00 GMT
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @param headers The headers instance to delete the cookie from
|
|
275
|
+
* @param name Name of cookie
|
|
276
|
+
* @param attributes Additional cookie attributes
|
|
277
|
+
*/
|
|
278
|
+
export function deleteCookie(
|
|
279
|
+
headers: Headers,
|
|
280
|
+
name: string,
|
|
281
|
+
attributes?: { path?: string; domain?: string },
|
|
282
|
+
) {
|
|
283
|
+
setCookie(headers, {
|
|
284
|
+
name: name,
|
|
285
|
+
value: "",
|
|
286
|
+
expires: new Date(0),
|
|
287
|
+
...attributes,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function parseSetCookie(value: string): Cookie | null {
|
|
292
|
+
const attrs = value
|
|
293
|
+
.split(";")
|
|
294
|
+
.map((attr) =>
|
|
295
|
+
attr
|
|
296
|
+
.trim()
|
|
297
|
+
.split("=")
|
|
298
|
+
.map((keyOrValue) => keyOrValue.trim())
|
|
299
|
+
);
|
|
300
|
+
const cookie: Cookie = {
|
|
301
|
+
name: attrs[0][0],
|
|
302
|
+
value: attrs[0][1],
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
for (const [key, value] of attrs.slice(1)) {
|
|
306
|
+
switch (key.toLocaleLowerCase()) {
|
|
307
|
+
case "expires":
|
|
308
|
+
cookie.expires = new Date(value);
|
|
309
|
+
break;
|
|
310
|
+
case "max-age":
|
|
311
|
+
cookie.maxAge = Number(value);
|
|
312
|
+
if (cookie.maxAge < 0) {
|
|
313
|
+
console.warn(
|
|
314
|
+
"Max-Age must be an integer superior or equal to 0. Cookie ignored.",
|
|
315
|
+
);
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
break;
|
|
319
|
+
case "domain":
|
|
320
|
+
cookie.domain = value;
|
|
321
|
+
break;
|
|
322
|
+
case "path":
|
|
323
|
+
cookie.path = value;
|
|
324
|
+
break;
|
|
325
|
+
case "secure":
|
|
326
|
+
cookie.secure = true;
|
|
327
|
+
break;
|
|
328
|
+
case "httponly":
|
|
329
|
+
cookie.httpOnly = true;
|
|
330
|
+
break;
|
|
331
|
+
case "samesite":
|
|
332
|
+
cookie.sameSite = value as Cookie["sameSite"];
|
|
333
|
+
break;
|
|
334
|
+
default:
|
|
335
|
+
if (!Array.isArray(cookie.unparsed)) {
|
|
336
|
+
cookie.unparsed = [];
|
|
337
|
+
}
|
|
338
|
+
cookie.unparsed.push([key, value].join("="));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (cookie.name.startsWith("__Secure-")) {
|
|
342
|
+
/** This requirement is mentioned in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie but not the RFC. */
|
|
343
|
+
if (!cookie.secure) {
|
|
344
|
+
console.warn(
|
|
345
|
+
"Cookies with names starting with `__Secure-` must be set with the secure flag. Cookie ignored.",
|
|
346
|
+
);
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (cookie.name.startsWith("__Host-")) {
|
|
351
|
+
if (!cookie.secure) {
|
|
352
|
+
console.warn(
|
|
353
|
+
"Cookies with names starting with `__Host-` must be set with the secure flag. Cookie ignored.",
|
|
354
|
+
);
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
if (cookie.domain !== undefined) {
|
|
358
|
+
console.warn(
|
|
359
|
+
"Cookies with names starting with `__Host-` must not have a domain specified. Cookie ignored.",
|
|
360
|
+
);
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
if (cookie.path !== "/") {
|
|
364
|
+
console.warn(
|
|
365
|
+
"Cookies with names starting with `__Host-` must have path be `/`. Cookie has been ignored.",
|
|
366
|
+
);
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return cookie;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Parse set-cookies of a header
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```ts
|
|
378
|
+
* import { getSetCookies } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";
|
|
379
|
+
*
|
|
380
|
+
* const headers = new Headers([
|
|
381
|
+
* ["Set-Cookie", "lulu=meow; Secure; Max-Age=3600"],
|
|
382
|
+
* ["Set-Cookie", "booya=kasha; HttpOnly; Path=/"],
|
|
383
|
+
* ]);
|
|
384
|
+
*
|
|
385
|
+
* const cookies = getSetCookies(headers);
|
|
386
|
+
* console.log(cookies); // [{ name: "lulu", value: "meow", secure: true, maxAge: 3600 }, { name: "booya", value: "kahsa", httpOnly: true, path: "/ }]
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
* @param headers The headers instance to get set-cookies from
|
|
390
|
+
* @return List of cookies
|
|
391
|
+
*/
|
|
392
|
+
export function getSetCookies(headers: Headers): Cookie[] {
|
|
393
|
+
if (!headers.has("set-cookie")) {
|
|
394
|
+
return [];
|
|
395
|
+
}
|
|
396
|
+
return [...headers.entries()]
|
|
397
|
+
.filter(([key]) => key === "set-cookie")
|
|
398
|
+
.map(([_, value]) => value)
|
|
399
|
+
/** Parse each `set-cookie` header separately */
|
|
400
|
+
.map(parseSetCookie)
|
|
401
|
+
/** Skip empty cookies */
|
|
402
|
+
.filter(Boolean) as Cookie[];
|
|
403
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
// This module provides an interface to `Deno.core`. For environments
|
|
4
|
+
// that don't have access to `Deno.core` some APIs are polyfilled, while
|
|
5
|
+
// some are unavailble and throw on call.
|
|
6
|
+
// Note: deno_std shouldn't use Deno.core namespace. We should minimize these
|
|
7
|
+
// usages.
|
|
8
|
+
|
|
9
|
+
// deno-lint-ignore no-explicit-any
|
|
10
|
+
export let core: any;
|
|
11
|
+
|
|
12
|
+
// deno-lint-ignore no-explicit-any
|
|
13
|
+
const { Deno } = globalThis as any;
|
|
14
|
+
|
|
15
|
+
// @ts-ignore Deno.core is not defined in types
|
|
16
|
+
if (Deno?.[Deno.internal]?.core) {
|
|
17
|
+
// @ts-ignore Deno[Deno.internal].core is not defined in types
|
|
18
|
+
core = Deno[Deno.internal].core;
|
|
19
|
+
} else if (Deno?.core) {
|
|
20
|
+
// @ts-ignore Deno.core is not defined in types
|
|
21
|
+
core = Deno.core;
|
|
22
|
+
} else {
|
|
23
|
+
core = {
|
|
24
|
+
runMicrotasks() {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"Deno.core.runMicrotasks() is not supported in this environment",
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
setHasTickScheduled() {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Deno.core.setHasTickScheduled() is not supported in this environment",
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
hasTickScheduled() {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Deno.core.hasTickScheduled() is not supported in this environment",
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
setNextTickCallback: undefined,
|
|
40
|
+
setMacrotaskCallback() {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"Deno.core.setNextTickCallback() is not supported in this environment",
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
evalContext(_code: string, _filename: string) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"Deno.core.evalContext is not supported in this environment",
|
|
48
|
+
);
|
|
49
|
+
},
|
|
50
|
+
encode(chunk: string): Uint8Array {
|
|
51
|
+
return new TextEncoder().encode(chunk);
|
|
52
|
+
},
|
|
53
|
+
eventLoopHasMoreWork(): boolean {
|
|
54
|
+
return false;
|
|
55
|
+
},
|
|
56
|
+
isProxy(): boolean {
|
|
57
|
+
return false;
|
|
58
|
+
},
|
|
59
|
+
getPromiseDetails(_promise: Promise<unknown>): [number, unknown] {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"Deno.core.getPromiseDetails is not supported in this environment",
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
setPromiseHooks() {
|
|
65
|
+
throw new Error(
|
|
66
|
+
"Deno.core.setPromiseHooks is not supported in this environment",
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
ops: {
|
|
70
|
+
op_napi_open(_filename: string) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Node API is not supported in this environment",
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|