@stryke/http 0.8.5 → 0.10.0
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/dist/agent.cjs +84 -0
- package/dist/agent.d.ts +36 -0
- package/dist/agent.mjs +2 -0
- package/dist/fetch.cjs +38 -0
- package/dist/fetch.d.ts +19 -0
- package/dist/fetch.mjs +1 -0
- package/dist/format-data-uri.cjs +24 -2
- package/dist/format-data-uri.d.ts +40 -0
- package/dist/format-data-uri.mjs +1 -1
- package/dist/get-free-port.cjs +15 -0
- package/dist/get-free-port.d.ts +6 -0
- package/dist/get-free-port.mjs +1 -0
- package/dist/http-proxy.cjs +71 -0
- package/dist/http-proxy.d.ts +39 -0
- package/dist/http-proxy.mjs +3 -0
- package/dist/https-proxy.cjs +88 -0
- package/dist/https-proxy.d.ts +43 -0
- package/dist/https-proxy.mjs +4 -0
- package/dist/index.cjs +63 -8
- package/dist/index.d.ts +7 -2
- package/dist/index.mjs +1 -1
- package/dist/parse-response.cjs +63 -0
- package/dist/parse-response.d.ts +12 -0
- package/dist/parse-response.mjs +4 -0
- package/dist/proxy-agent.cjs +14 -0
- package/dist/proxy-agent.d.ts +5 -0
- package/dist/proxy-agent.mjs +1 -0
- package/package.json +82 -18
- package/dist/cookie.cjs +0 -187
- package/dist/cookie.d.ts +0 -37
- package/dist/cookie.mjs +0 -1
- package/dist/types.cjs +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/types.mjs +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./agent";
|
|
2
|
+
export * from "./fetch";
|
|
2
3
|
export * from "./format-data-uri";
|
|
3
|
-
export * from "./
|
|
4
|
+
export * from "./get-free-port";
|
|
5
|
+
export * from "./http-proxy";
|
|
6
|
+
export * from "./https-proxy";
|
|
7
|
+
export * from "./parse-response";
|
|
8
|
+
export * from "./proxy-agent";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./
|
|
1
|
+
export*from"./agent";export*from"./fetch";export*from"./format-data-uri";export*from"./get-free-port";export*from"./http-proxy";export*from"./https-proxy";export*from"./parse-response";export*from"./proxy-agent";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseProxyResponse = parseProxyResponse;
|
|
7
|
+
var _nodeBuffer = require("node:buffer");
|
|
8
|
+
async function parseProxyResponse(e) {
|
|
9
|
+
return new Promise((g, o) => {
|
|
10
|
+
let p = 0;
|
|
11
|
+
const m = [];
|
|
12
|
+
function t() {
|
|
13
|
+
const r = e.read();
|
|
14
|
+
r ? v(r) : e.once("readable", t);
|
|
15
|
+
}
|
|
16
|
+
function f() {
|
|
17
|
+
e.removeListener("end", l), e.removeListener("error", y), e.removeListener("readable", t);
|
|
18
|
+
}
|
|
19
|
+
function l() {
|
|
20
|
+
f(), o(new Error("Proxy connection ended before receiving CONNECT response"));
|
|
21
|
+
}
|
|
22
|
+
function y(r) {
|
|
23
|
+
f(), o(r);
|
|
24
|
+
}
|
|
25
|
+
function v(r) {
|
|
26
|
+
m.push(r), p += r.length;
|
|
27
|
+
const a = _nodeBuffer.Buffer.concat(m, p),
|
|
28
|
+
h = a.indexOf(`\r
|
|
29
|
+
\r
|
|
30
|
+
`);
|
|
31
|
+
if (h === -1) {
|
|
32
|
+
t();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const C = a.subarray(0, h).toString("ascii").split(`\r
|
|
36
|
+
`),
|
|
37
|
+
b = C.shift();
|
|
38
|
+
if (!b) return e.destroy(), o(new Error("No header received from proxy CONNECT response"));
|
|
39
|
+
const x = b.split(" "),
|
|
40
|
+
E = +x[1],
|
|
41
|
+
H = x.slice(2).join(" "),
|
|
42
|
+
s = {};
|
|
43
|
+
for (const n of C) {
|
|
44
|
+
if (!n) continue;
|
|
45
|
+
const c = n.indexOf(":");
|
|
46
|
+
if (c === -1) return e.destroy(), o(new Error(`Invalid header from proxy CONNECT response: "${n}"`));
|
|
47
|
+
const d = n.slice(0, c).toLowerCase(),
|
|
48
|
+
u = n.slice(c + 1).trimStart(),
|
|
49
|
+
i = s[d];
|
|
50
|
+
typeof i == "string" ? s[d] = [i, u] : Array.isArray(i) ? i.push(u) : s[d] = u;
|
|
51
|
+
}
|
|
52
|
+
f(), g({
|
|
53
|
+
connect: {
|
|
54
|
+
statusCode: E,
|
|
55
|
+
statusText: H,
|
|
56
|
+
headers: s
|
|
57
|
+
},
|
|
58
|
+
buffered: a
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
e.on("error", y), e.on("end", l), t();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import type { IncomingHttpHeaders } from "node:http";
|
|
3
|
+
import type { Readable } from "node:stream";
|
|
4
|
+
export interface ConnectResponse {
|
|
5
|
+
statusCode: number;
|
|
6
|
+
statusText: string;
|
|
7
|
+
headers: IncomingHttpHeaders;
|
|
8
|
+
}
|
|
9
|
+
export declare function parseProxyResponse(socket: Readable): Promise<{
|
|
10
|
+
connect: ConnectResponse;
|
|
11
|
+
buffered: Buffer;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{Buffer as L}from"node:buffer";export async function parseProxyResponse(e){return new Promise((g,o)=>{let p=0;const m=[];function t(){const r=e.read();r?v(r):e.once("readable",t)}function f(){e.removeListener("end",l),e.removeListener("error",y),e.removeListener("readable",t)}function l(){f(),o(new Error("Proxy connection ended before receiving CONNECT response"))}function y(r){f(),o(r)}function v(r){m.push(r),p+=r.length;const a=L.concat(m,p),h=a.indexOf(`\r
|
|
2
|
+
\r
|
|
3
|
+
`);if(h===-1){t();return}const C=a.subarray(0,h).toString("ascii").split(`\r
|
|
4
|
+
`),b=C.shift();if(!b)return e.destroy(),o(new Error("No header received from proxy CONNECT response"));const x=b.split(" "),E=+x[1],H=x.slice(2).join(" "),s={};for(const n of C){if(!n)continue;const c=n.indexOf(":");if(c===-1)return e.destroy(),o(new Error(`Invalid header from proxy CONNECT response: "${n}"`));const d=n.slice(0,c).toLowerCase(),u=n.slice(c+1).trimStart(),i=s[d];typeof i=="string"?s[d]=[i,u]:Array.isArray(i)?i.push(u):s[d]=u}f(),g({connect:{statusCode:E,statusText:H,headers:s},buffered:a})}e.on("error",y),e.on("end",l),t()})}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getProxyAgent = getProxyAgent;
|
|
7
|
+
var _httpProxy = require("./http-proxy.cjs");
|
|
8
|
+
var _httpsProxy = require("./https-proxy.cjs");
|
|
9
|
+
function getProxyAgent() {
|
|
10
|
+
const t = process.env.https_proxy || process.env.HTTPS_PROXY;
|
|
11
|
+
if (t) return new _httpsProxy.HttpsProxyAgent(t);
|
|
12
|
+
const e = process.env.http_proxy || process.env.HTTP_PROXY;
|
|
13
|
+
if (e) return new _httpProxy.HttpProxyAgent(e);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{HttpProxyAgent as r}from"./http-proxy";import{HttpsProxyAgent as n}from"./https-proxy";export function getProxyAgent(){const t=process.env.https_proxy||process.env.HTTPS_PROXY;if(t)return new n(t);const e=process.env.http_proxy||process.env.HTTP_PROXY;if(e)return new r(e)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing HTTP communication utilities used by Storm Software.",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"private": false,
|
|
12
12
|
"devDependencies": { "@types/node": "^22.14.0" },
|
|
13
13
|
"publishConfig": { "access": "public" },
|
|
14
|
-
"dependencies": { "@stryke/type-checks": "^0.3.
|
|
14
|
+
"dependencies": { "@stryke/type-checks": "^0.3.10" },
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"files": ["dist/**/*"],
|
|
17
17
|
"homepage": "https://stormsoftware.com",
|
|
@@ -55,13 +55,33 @@
|
|
|
55
55
|
}
|
|
56
56
|
],
|
|
57
57
|
"exports": {
|
|
58
|
-
"./
|
|
59
|
-
"import": {
|
|
58
|
+
"./proxy-agent": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/proxy-agent.d.ts",
|
|
61
|
+
"default": "./dist/proxy-agent.mjs"
|
|
62
|
+
},
|
|
60
63
|
"require": {
|
|
61
|
-
"types": "./dist/
|
|
62
|
-
"default": "./dist/
|
|
64
|
+
"types": "./dist/proxy-agent.d.ts",
|
|
65
|
+
"default": "./dist/proxy-agent.cjs"
|
|
63
66
|
},
|
|
64
|
-
"default": {
|
|
67
|
+
"default": {
|
|
68
|
+
"types": "./dist/proxy-agent.d.ts",
|
|
69
|
+
"default": "./dist/proxy-agent.mjs"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"./parse-response": {
|
|
73
|
+
"import": {
|
|
74
|
+
"types": "./dist/parse-response.d.ts",
|
|
75
|
+
"default": "./dist/parse-response.mjs"
|
|
76
|
+
},
|
|
77
|
+
"require": {
|
|
78
|
+
"types": "./dist/parse-response.d.ts",
|
|
79
|
+
"default": "./dist/parse-response.cjs"
|
|
80
|
+
},
|
|
81
|
+
"default": {
|
|
82
|
+
"types": "./dist/parse-response.d.ts",
|
|
83
|
+
"default": "./dist/parse-response.mjs"
|
|
84
|
+
}
|
|
65
85
|
},
|
|
66
86
|
"./index": {
|
|
67
87
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
@@ -71,6 +91,48 @@
|
|
|
71
91
|
},
|
|
72
92
|
"default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
|
|
73
93
|
},
|
|
94
|
+
"./https-proxy": {
|
|
95
|
+
"import": {
|
|
96
|
+
"types": "./dist/https-proxy.d.ts",
|
|
97
|
+
"default": "./dist/https-proxy.mjs"
|
|
98
|
+
},
|
|
99
|
+
"require": {
|
|
100
|
+
"types": "./dist/https-proxy.d.ts",
|
|
101
|
+
"default": "./dist/https-proxy.cjs"
|
|
102
|
+
},
|
|
103
|
+
"default": {
|
|
104
|
+
"types": "./dist/https-proxy.d.ts",
|
|
105
|
+
"default": "./dist/https-proxy.mjs"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"./http-proxy": {
|
|
109
|
+
"import": {
|
|
110
|
+
"types": "./dist/http-proxy.d.ts",
|
|
111
|
+
"default": "./dist/http-proxy.mjs"
|
|
112
|
+
},
|
|
113
|
+
"require": {
|
|
114
|
+
"types": "./dist/http-proxy.d.ts",
|
|
115
|
+
"default": "./dist/http-proxy.cjs"
|
|
116
|
+
},
|
|
117
|
+
"default": {
|
|
118
|
+
"types": "./dist/http-proxy.d.ts",
|
|
119
|
+
"default": "./dist/http-proxy.mjs"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"./get-free-port": {
|
|
123
|
+
"import": {
|
|
124
|
+
"types": "./dist/get-free-port.d.ts",
|
|
125
|
+
"default": "./dist/get-free-port.mjs"
|
|
126
|
+
},
|
|
127
|
+
"require": {
|
|
128
|
+
"types": "./dist/get-free-port.d.ts",
|
|
129
|
+
"default": "./dist/get-free-port.cjs"
|
|
130
|
+
},
|
|
131
|
+
"default": {
|
|
132
|
+
"types": "./dist/get-free-port.d.ts",
|
|
133
|
+
"default": "./dist/get-free-port.mjs"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
74
136
|
"./format-data-uri": {
|
|
75
137
|
"import": {
|
|
76
138
|
"types": "./dist/format-data-uri.d.ts",
|
|
@@ -85,19 +147,21 @@
|
|
|
85
147
|
"default": "./dist/format-data-uri.mjs"
|
|
86
148
|
}
|
|
87
149
|
},
|
|
88
|
-
"./
|
|
89
|
-
"import": {
|
|
90
|
-
|
|
91
|
-
"
|
|
150
|
+
"./fetch": {
|
|
151
|
+
"import": { "types": "./dist/fetch.d.ts", "default": "./dist/fetch.mjs" },
|
|
152
|
+
"require": {
|
|
153
|
+
"types": "./dist/fetch.d.ts",
|
|
154
|
+
"default": "./dist/fetch.cjs"
|
|
92
155
|
},
|
|
156
|
+
"default": { "types": "./dist/fetch.d.ts", "default": "./dist/fetch.mjs" }
|
|
157
|
+
},
|
|
158
|
+
"./agent": {
|
|
159
|
+
"import": { "types": "./dist/agent.d.ts", "default": "./dist/agent.mjs" },
|
|
93
160
|
"require": {
|
|
94
|
-
"types": "./dist/
|
|
95
|
-
"default": "./dist/
|
|
161
|
+
"types": "./dist/agent.d.ts",
|
|
162
|
+
"default": "./dist/agent.cjs"
|
|
96
163
|
},
|
|
97
|
-
"default": {
|
|
98
|
-
"types": "./dist/cookie.d.ts",
|
|
99
|
-
"default": "./dist/cookie.mjs"
|
|
100
|
-
}
|
|
164
|
+
"default": { "types": "./dist/agent.d.ts", "default": "./dist/agent.mjs" }
|
|
101
165
|
},
|
|
102
166
|
".": {
|
|
103
167
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
@@ -112,5 +176,5 @@
|
|
|
112
176
|
"main": "./dist/index.cjs",
|
|
113
177
|
"module": "./dist/index.mjs",
|
|
114
178
|
"types": "./dist/index.d.ts",
|
|
115
|
-
"gitHead": "
|
|
179
|
+
"gitHead": "4074c4a56f6e2c42ca4c39c30df5309c19024c7b"
|
|
116
180
|
}
|
package/dist/cookie.cjs
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseCookie = parseCookie;
|
|
7
|
-
exports.parseSetCookie = parseSetCookie;
|
|
8
|
-
exports.serializeCookie = serializeCookie;
|
|
9
|
-
exports.splitSetCookieString = splitSetCookieString;
|
|
10
|
-
var _typeChecks = require("@stryke/type-checks");
|
|
11
|
-
function parseCookie(r, c) {
|
|
12
|
-
if (!(0, _typeChecks.isString)(r)) throw new Error("argument str must be a string");
|
|
13
|
-
const i = {},
|
|
14
|
-
e = c ?? {},
|
|
15
|
-
o = e.decode ?? (t => t.includes("%") ? decodeURIComponent(t) : t);
|
|
16
|
-
let a = 0;
|
|
17
|
-
for (; a < r.length;) {
|
|
18
|
-
const t = r.indexOf("=", a);
|
|
19
|
-
if (t === -1) break;
|
|
20
|
-
let n = r.indexOf(";", a);
|
|
21
|
-
if (n === -1) n = r.length;else if (n < t) {
|
|
22
|
-
a = r.lastIndexOf(";", t - 1) + 1;
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
const s = r.slice(a, t).trim();
|
|
26
|
-
if (e?.filter && !e?.filter(s)) {
|
|
27
|
-
a = n + 1;
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (i[s] === void 0) {
|
|
31
|
-
let l = r.slice(t + 1, n).trim();
|
|
32
|
-
l.codePointAt(0) === 34 && (l = l.slice(1, -1));
|
|
33
|
-
try {
|
|
34
|
-
i[s] = o(l);
|
|
35
|
-
} catch {
|
|
36
|
-
i[s] = l;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
a = n + 1;
|
|
40
|
-
}
|
|
41
|
-
return i;
|
|
42
|
-
}
|
|
43
|
-
function parseSetCookie(r, c) {
|
|
44
|
-
const i = (r || "").split(";").filter(s => (0, _typeChecks.isString)(s) && !!s.trim()),
|
|
45
|
-
e = i.shift() || "";
|
|
46
|
-
let o = "",
|
|
47
|
-
a = "";
|
|
48
|
-
const t = e.split("=");
|
|
49
|
-
t.length > 1 ? (o = t.shift(), a = t.join("=")) : a = e;
|
|
50
|
-
try {
|
|
51
|
-
a = c?.decode === !1 ? a : (c?.decode ?? decodeURIComponent)(a);
|
|
52
|
-
} catch {}
|
|
53
|
-
const n = {
|
|
54
|
-
name: o,
|
|
55
|
-
value: a
|
|
56
|
-
};
|
|
57
|
-
for (const s of i) {
|
|
58
|
-
const l = s.split("="),
|
|
59
|
-
f = (l.shift() || "").trimStart().toLowerCase(),
|
|
60
|
-
m = l.join("=");
|
|
61
|
-
switch (f) {
|
|
62
|
-
case "expires":
|
|
63
|
-
{
|
|
64
|
-
n.expires = new Date(m);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
case "max-age":
|
|
68
|
-
{
|
|
69
|
-
n.maxAge = Number.parseInt(m, 10);
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
case "secure":
|
|
73
|
-
{
|
|
74
|
-
n.secure = !0;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case "httponly":
|
|
78
|
-
{
|
|
79
|
-
n.httpOnly = !0;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
case "samesite":
|
|
83
|
-
{
|
|
84
|
-
n.sameSite = m;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
default:
|
|
88
|
-
n[f] = m;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return n;
|
|
92
|
-
}
|
|
93
|
-
const u = /^[\t\u0020-\u007E\u0080-\u00FF]+$/;
|
|
94
|
-
function serializeCookie(r, c, i) {
|
|
95
|
-
const e = i ?? {},
|
|
96
|
-
o = e.encode ?? encodeURIComponent;
|
|
97
|
-
if (!(0, _typeChecks.isFunction)(o)) throw new Error("option encode is invalid");
|
|
98
|
-
if (!u.test(r)) throw new Error("argument name is invalid");
|
|
99
|
-
const a = o(c);
|
|
100
|
-
if (a && !u.test(a)) throw new Error("argument val is invalid");
|
|
101
|
-
let t = `${r}=${a}`;
|
|
102
|
-
if (!(0, _typeChecks.isSet)(e.maxAge)) {
|
|
103
|
-
const n = Number(e.maxAge);
|
|
104
|
-
if (Number.isNaN(n) || !Number.isFinite(n)) throw new TypeError("option maxAge is invalid");
|
|
105
|
-
t += `; Max-Age=${Math.floor(n)}`;
|
|
106
|
-
}
|
|
107
|
-
if (e.domain) {
|
|
108
|
-
if (!u.test(e.domain)) throw new Error("option domain is invalid");
|
|
109
|
-
t += `; Domain=${e.domain}`;
|
|
110
|
-
}
|
|
111
|
-
if (e.path) {
|
|
112
|
-
if (!u.test(e.path)) throw new Error("option path is invalid");
|
|
113
|
-
t += `; Path=${e.path}`;
|
|
114
|
-
}
|
|
115
|
-
if (e.expires) {
|
|
116
|
-
if (!(0, _typeChecks.isDate)(e.expires) || Number.isNaN(e.expires.valueOf())) throw new Error("option expires is invalid");
|
|
117
|
-
t += `; Expires=${e.expires.toUTCString()}`;
|
|
118
|
-
}
|
|
119
|
-
if (e.httpOnly && (t += "; HttpOnly"), e.secure && (t += "; Secure"), e.priority) switch ((0, _typeChecks.isString)(e.priority) ? e.priority.toLowerCase() : e.priority) {
|
|
120
|
-
case "low":
|
|
121
|
-
{
|
|
122
|
-
t += "; Priority=Low";
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
case "medium":
|
|
126
|
-
{
|
|
127
|
-
t += "; Priority=Medium";
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
case "high":
|
|
131
|
-
{
|
|
132
|
-
t += "; Priority=High";
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
default:
|
|
136
|
-
throw new Error("option priority is invalid");
|
|
137
|
-
}
|
|
138
|
-
if (e.sameSite) switch ((0, _typeChecks.isString)(e.sameSite) ? e.sameSite.toLowerCase() : e.sameSite) {
|
|
139
|
-
case !0:
|
|
140
|
-
{
|
|
141
|
-
t += "; SameSite=Strict";
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case "lax":
|
|
145
|
-
{
|
|
146
|
-
t += "; SameSite=Lax";
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
case "strict":
|
|
150
|
-
{
|
|
151
|
-
t += "; SameSite=Strict";
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case "none":
|
|
155
|
-
{
|
|
156
|
-
t += "; SameSite=None";
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
default:
|
|
160
|
-
throw new Error("option sameSite is invalid");
|
|
161
|
-
}
|
|
162
|
-
return e.partitioned && (t += "; Partitioned"), t;
|
|
163
|
-
}
|
|
164
|
-
function splitSetCookieString(r) {
|
|
165
|
-
if (Array.isArray(r)) return r.flatMap(f => splitSetCookieString(f));
|
|
166
|
-
if (!(0, _typeChecks.isString)(r)) return [];
|
|
167
|
-
const c = [];
|
|
168
|
-
let i = 0,
|
|
169
|
-
e,
|
|
170
|
-
o,
|
|
171
|
-
a,
|
|
172
|
-
t,
|
|
173
|
-
n;
|
|
174
|
-
const s = () => {
|
|
175
|
-
for (; i < r.length && /\s/.test(r.charAt(i));) i += 1;
|
|
176
|
-
return i < r.length;
|
|
177
|
-
},
|
|
178
|
-
l = () => (o = r.charAt(i), o !== "=" && o !== ";" && o !== ",");
|
|
179
|
-
for (; i < r.length;) {
|
|
180
|
-
for (e = i, n = !1; s();) if (o = r.charAt(i), o === ",") {
|
|
181
|
-
for (a = i, i += 1, s(), t = i; i < r.length && l();) i += 1;
|
|
182
|
-
i < r.length && r.charAt(i) === "=" ? (n = !0, i = t, c.push(r.slice(e, a)), e = i) : i = a + 1;
|
|
183
|
-
} else i += 1;
|
|
184
|
-
(!n || i >= r.length) && c.push(r.slice(e));
|
|
185
|
-
}
|
|
186
|
-
return c;
|
|
187
|
-
}
|
package/dist/cookie.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { CookieParseOptions, CookieSerializeOptions, SetCookie, SetCookieParseOptions } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Parse an HTTP Cookie header string and returning an object of all cookie
|
|
4
|
-
* name-value pairs.
|
|
5
|
-
*
|
|
6
|
-
* @param strCookie - the string representing a `Cookie` header value
|
|
7
|
-
* @param options - object containing parsing options
|
|
8
|
-
* @returns an object with the parsed cookies
|
|
9
|
-
*/
|
|
10
|
-
export declare function parseCookie(strCookie: string, options?: CookieParseOptions): Record<string, string>;
|
|
11
|
-
/**
|
|
12
|
-
* Parse a [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) header string into an object.
|
|
13
|
-
*
|
|
14
|
-
* @param setCookieValue - the string representing a `Set-Cookie` header value
|
|
15
|
-
* @param options - object containing parsing options
|
|
16
|
-
* @returns an object with the parsed cookie
|
|
17
|
-
*/
|
|
18
|
-
export declare function parseSetCookie(setCookieValue: string, options?: SetCookieParseOptions): SetCookie;
|
|
19
|
-
/**
|
|
20
|
-
* Serialize a cookie name-value pair into a `Set-Cookie` header string.
|
|
21
|
-
*
|
|
22
|
-
* @param name - the name for the cookie
|
|
23
|
-
* @param value - value to set the cookie to
|
|
24
|
-
* @param options - object containing serialization options
|
|
25
|
-
* @returns a `Set-Cookie` header string
|
|
26
|
-
*/
|
|
27
|
-
export declare function serializeCookie(name: string, value: string, options?: CookieSerializeOptions): string;
|
|
28
|
-
/**
|
|
29
|
-
* Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
30
|
-
* that are within a single set-cookie field-value, such as in the Expires portion.
|
|
31
|
-
*
|
|
32
|
-
* See https://tools.ietf.org/html/rfc2616#section-4.2
|
|
33
|
-
*
|
|
34
|
-
* @param strCookie - The string representing a `Set-Cookie` header value
|
|
35
|
-
* @returns An array of strings representing individual `Set-Cookie` header values
|
|
36
|
-
*/
|
|
37
|
-
export declare function splitSetCookieString(strCookie: string | string[]): string[];
|
package/dist/cookie.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isDate as h,isFunction as d,isSet as g,isString as p}from"@stryke/type-checks";export function parseCookie(r,c){if(!p(r))throw new Error("argument str must be a string");const i={},e=c??{},o=e.decode??(t=>t.includes("%")?decodeURIComponent(t):t);let a=0;for(;a<r.length;){const t=r.indexOf("=",a);if(t===-1)break;let n=r.indexOf(";",a);if(n===-1)n=r.length;else if(n<t){a=r.lastIndexOf(";",t-1)+1;continue}const s=r.slice(a,t).trim();if(e?.filter&&!e?.filter(s)){a=n+1;continue}if(i[s]===void 0){let l=r.slice(t+1,n).trim();l.codePointAt(0)===34&&(l=l.slice(1,-1));try{i[s]=o(l)}catch{i[s]=l}}a=n+1}return i}export function parseSetCookie(r,c){const i=(r||"").split(";").filter(s=>p(s)&&!!s.trim()),e=i.shift()||"";let o="",a="";const t=e.split("=");t.length>1?(o=t.shift(),a=t.join("=")):a=e;try{a=c?.decode===!1?a:(c?.decode??decodeURIComponent)(a)}catch{}const n={name:o,value:a};for(const s of i){const l=s.split("="),f=(l.shift()||"").trimStart().toLowerCase(),m=l.join("=");switch(f){case"expires":{n.expires=new Date(m);break}case"max-age":{n.maxAge=Number.parseInt(m,10);break}case"secure":{n.secure=!0;break}case"httponly":{n.httpOnly=!0;break}case"samesite":{n.sameSite=m;break}default:n[f]=m}}return n}const u=/^[\t\u0020-\u007E\u0080-\u00FF]+$/;export function serializeCookie(r,c,i){const e=i??{},o=e.encode??encodeURIComponent;if(!d(o))throw new Error("option encode is invalid");if(!u.test(r))throw new Error("argument name is invalid");const a=o(c);if(a&&!u.test(a))throw new Error("argument val is invalid");let t=`${r}=${a}`;if(!g(e.maxAge)){const n=Number(e.maxAge);if(Number.isNaN(n)||!Number.isFinite(n))throw new TypeError("option maxAge is invalid");t+=`; Max-Age=${Math.floor(n)}`}if(e.domain){if(!u.test(e.domain))throw new Error("option domain is invalid");t+=`; Domain=${e.domain}`}if(e.path){if(!u.test(e.path))throw new Error("option path is invalid");t+=`; Path=${e.path}`}if(e.expires){if(!h(e.expires)||Number.isNaN(e.expires.valueOf()))throw new Error("option expires is invalid");t+=`; Expires=${e.expires.toUTCString()}`}if(e.httpOnly&&(t+="; HttpOnly"),e.secure&&(t+="; Secure"),e.priority)switch(p(e.priority)?e.priority.toLowerCase():e.priority){case"low":{t+="; Priority=Low";break}case"medium":{t+="; Priority=Medium";break}case"high":{t+="; Priority=High";break}default:throw new Error("option priority is invalid")}if(e.sameSite)switch(p(e.sameSite)?e.sameSite.toLowerCase():e.sameSite){case!0:{t+="; SameSite=Strict";break}case"lax":{t+="; SameSite=Lax";break}case"strict":{t+="; SameSite=Strict";break}case"none":{t+="; SameSite=None";break}default:throw new Error("option sameSite is invalid")}return e.partitioned&&(t+="; Partitioned"),t}export function splitSetCookieString(r){if(Array.isArray(r))return r.flatMap(f=>splitSetCookieString(f));if(!p(r))return[];const c=[];let i=0,e,o,a,t,n;const s=()=>{for(;i<r.length&&/\s/.test(r.charAt(i));)i+=1;return i<r.length},l=()=>(o=r.charAt(i),o!=="="&&o!==";"&&o!==",");for(;i<r.length;){for(e=i,n=!1;s();)if(o=r.charAt(i),o===","){for(a=i,i+=1,s(),t=i;i<r.length&&l();)i+=1;i<r.length&&r.charAt(i)==="="?(n=!0,i=t,c.push(r.slice(e,a)),e=i):i=a+1}else i+=1;(!n||i>=r.length)&&c.push(r.slice(e))}return c}
|
package/dist/types.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|