@procedures/http 0.0.0-stage → 0.2.3
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/LICENSE +21 -0
- package/README.md +118 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/address.d.ts +31 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +214 -0
- package/dist/address.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +18 -0
- package/dist/errors.js.map +1 -0
- package/dist/exchange.d.ts +102 -0
- package/dist/exchange.d.ts.map +1 -0
- package/dist/exchange.js +322 -0
- package/dist/exchange.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +41 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +205 -0
- package/dist/module.js.map +1 -0
- package/dist/parsers.d.ts +37 -0
- package/dist/parsers.d.ts.map +1 -0
- package/dist/parsers.js +175 -0
- package/dist/parsers.js.map +1 -0
- package/dist/policy.d.ts +94 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +140 -0
- package/dist/policy.js.map +1 -0
- package/dist/procedures/http/index.d.ts +5 -0
- package/dist/procedures/http/index.d.ts.map +1 -0
- package/dist/procedures/http/index.js +5 -0
- package/dist/procedures/http/index.js.map +1 -0
- package/dist/procedures/http/json.d.ts +14 -0
- package/dist/procedures/http/json.d.ts.map +1 -0
- package/dist/procedures/http/json.js +56 -0
- package/dist/procedures/http/json.js.map +1 -0
- package/dist/procedures/http/ndjson.d.ts +18 -0
- package/dist/procedures/http/ndjson.d.ts.map +1 -0
- package/dist/procedures/http/ndjson.js +65 -0
- package/dist/procedures/http/ndjson.js.map +1 -0
- package/dist/procedures/http/request.d.ts +14 -0
- package/dist/procedures/http/request.d.ts.map +1 -0
- package/dist/procedures/http/request.js +79 -0
- package/dist/procedures/http/request.js.map +1 -0
- package/dist/procedures/http/sse.d.ts +19 -0
- package/dist/procedures/http/sse.d.ts.map +1 -0
- package/dist/procedures/http/sse.js +66 -0
- package/dist/procedures/http/sse.js.map +1 -0
- package/dist/register.d.ts +6 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +8 -0
- package/dist/register.js.map +1 -0
- package/dist/scope.d.ts +53 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +107 -0
- package/dist/scope.js.map +1 -0
- package/dist/types.d.ts +102 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +79 -3
- package/src/address.ts +206 -0
- package/src/errors.ts +44 -0
- package/src/exchange.ts +381 -0
- package/src/index.ts +11 -0
- package/src/module.ts +257 -0
- package/src/parsers.ts +184 -0
- package/src/policy.ts +192 -0
- package/src/procedures/http/index.ts +4 -0
- package/src/procedures/http/json.ts +52 -0
- package/src/procedures/http/ndjson.ts +64 -0
- package/src/procedures/http/request.ts +72 -0
- package/src/procedures/http/sse.ts +65 -0
- package/src/register.ts +10 -0
- package/src/scope.ts +129 -0
- package/src/types.ts +127 -0
package/dist/address.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IP addresses: the parse, the CIDR ranges and the special-purpose ranges (roadmap R38).
|
|
3
|
+
*
|
|
4
|
+
* A public address is an address that the IANA registries of special-purpose addresses do not
|
|
5
|
+
* name. The HTTP procedures refuse each other address by default: loopback, private, link-local,
|
|
6
|
+
* shared (CGNAT), multicast, documentation, benchmarking and reserved addresses. An IPv6 address
|
|
7
|
+
* that holds an IPv4 address (IPv4-mapped, NAT64, 6to4) has the class of the IPv4 address.
|
|
8
|
+
*/
|
|
9
|
+
import { isIP } from "node:net";
|
|
10
|
+
/** The bytes of an IPv4 address in dotted decimal, or undefined. */
|
|
11
|
+
function ipv4Bytes(text) {
|
|
12
|
+
const parts = text.split(".");
|
|
13
|
+
if (parts.length !== 4)
|
|
14
|
+
return undefined;
|
|
15
|
+
const bytes = new Uint8Array(4);
|
|
16
|
+
for (let i = 0; i < 4; i++) {
|
|
17
|
+
const part = parts[i];
|
|
18
|
+
if (!/^(0|[1-9][0-9]{0,2})$/.test(part))
|
|
19
|
+
return undefined;
|
|
20
|
+
const value = Number(part);
|
|
21
|
+
if (value > 255)
|
|
22
|
+
return undefined;
|
|
23
|
+
bytes[i] = value;
|
|
24
|
+
}
|
|
25
|
+
return bytes;
|
|
26
|
+
}
|
|
27
|
+
/** The bytes of an IPv6 address, or undefined. A zone (`%eth0`) is removed. */
|
|
28
|
+
function ipv6Bytes(text) {
|
|
29
|
+
let address = text.startsWith("[") && text.endsWith("]") ? text.slice(1, -1) : text;
|
|
30
|
+
const zone = address.indexOf("%");
|
|
31
|
+
if (zone >= 0)
|
|
32
|
+
address = address.slice(0, zone);
|
|
33
|
+
if (isIP(address) !== 6)
|
|
34
|
+
return undefined;
|
|
35
|
+
// An IPv4 tail: "::ffff:1.2.3.4"
|
|
36
|
+
const groups = [];
|
|
37
|
+
const parseGroups = (part) => {
|
|
38
|
+
if (part === "")
|
|
39
|
+
return [];
|
|
40
|
+
const out = [];
|
|
41
|
+
for (const group of part.split(":")) {
|
|
42
|
+
if (group.includes(".")) {
|
|
43
|
+
const v4 = ipv4Bytes(group);
|
|
44
|
+
if (!v4)
|
|
45
|
+
return undefined;
|
|
46
|
+
out.push((v4[0] << 8) | v4[1], (v4[2] << 8) | v4[3]);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
if (!/^[0-9a-fA-F]{1,4}$/.test(group))
|
|
50
|
+
return undefined;
|
|
51
|
+
out.push(parseInt(group, 16));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
};
|
|
56
|
+
const double = address.indexOf("::");
|
|
57
|
+
if (double >= 0) {
|
|
58
|
+
const head = parseGroups(address.slice(0, double));
|
|
59
|
+
const tail = parseGroups(address.slice(double + 2));
|
|
60
|
+
if (!head || !tail || head.length + tail.length > 7)
|
|
61
|
+
return undefined;
|
|
62
|
+
groups.push(...head, ...new Array(8 - head.length - tail.length).fill(0), ...tail);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const all = parseGroups(address);
|
|
66
|
+
if (!all || all.length !== 8)
|
|
67
|
+
return undefined;
|
|
68
|
+
groups.push(...all);
|
|
69
|
+
}
|
|
70
|
+
const bytes = new Uint8Array(16);
|
|
71
|
+
groups.forEach((group, index) => {
|
|
72
|
+
bytes[index * 2] = group >> 8;
|
|
73
|
+
bytes[index * 2 + 1] = group & 0xff;
|
|
74
|
+
});
|
|
75
|
+
return bytes;
|
|
76
|
+
}
|
|
77
|
+
/** The bytes of an IPv4 or IPv6 address (brackets and a zone are allowed), or undefined. */
|
|
78
|
+
export function parseAddress(text) {
|
|
79
|
+
return ipv4Bytes(text) ?? ipv6Bytes(text);
|
|
80
|
+
}
|
|
81
|
+
/** The text of an address: dotted decimal for IPv4, the compressed form for IPv6. */
|
|
82
|
+
export function formatAddress(bytes) {
|
|
83
|
+
if (bytes.length === 4)
|
|
84
|
+
return [...bytes].join(".");
|
|
85
|
+
const groups = [];
|
|
86
|
+
for (let i = 0; i < 16; i += 2)
|
|
87
|
+
groups.push((bytes[i] << 8) | bytes[i + 1]);
|
|
88
|
+
// The longest run of two or more zero groups becomes "::"
|
|
89
|
+
let bestStart = -1;
|
|
90
|
+
let bestLength = 0;
|
|
91
|
+
for (let i = 0; i < 8;) {
|
|
92
|
+
if (groups[i] !== 0) {
|
|
93
|
+
i++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
let j = i;
|
|
97
|
+
while (j < 8 && groups[j] === 0)
|
|
98
|
+
j++;
|
|
99
|
+
if (j - i > bestLength && j - i >= 2) {
|
|
100
|
+
bestStart = i;
|
|
101
|
+
bestLength = j - i;
|
|
102
|
+
}
|
|
103
|
+
i = j;
|
|
104
|
+
}
|
|
105
|
+
const hex = groups.map((group) => group.toString(16));
|
|
106
|
+
if (bestStart < 0)
|
|
107
|
+
return hex.join(":");
|
|
108
|
+
return `${hex.slice(0, bestStart).join(":")}::${hex.slice(bestStart + bestLength).join(":")}`;
|
|
109
|
+
}
|
|
110
|
+
/** A range from CIDR text (`10.0.0.0/8`, `fd00::/8`) or one address. Undefined for bad text. */
|
|
111
|
+
export function parseRange(text) {
|
|
112
|
+
const slash = text.lastIndexOf("/");
|
|
113
|
+
const bytes = parseAddress(slash >= 0 ? text.slice(0, slash) : text);
|
|
114
|
+
if (!bytes)
|
|
115
|
+
return undefined;
|
|
116
|
+
const bits = bytes.length * 8;
|
|
117
|
+
if (slash < 0)
|
|
118
|
+
return { bytes, prefix: bits };
|
|
119
|
+
const prefixText = text.slice(slash + 1);
|
|
120
|
+
if (!/^[0-9]{1,3}$/.test(prefixText))
|
|
121
|
+
return undefined;
|
|
122
|
+
const prefix = Number(prefixText);
|
|
123
|
+
return prefix <= bits ? { bytes, prefix } : undefined;
|
|
124
|
+
}
|
|
125
|
+
/** True when the range has the address. An IPv4 range does not have an IPv6 address. */
|
|
126
|
+
export function rangeHas(range, address) {
|
|
127
|
+
if (range.bytes.length !== address.length)
|
|
128
|
+
return false;
|
|
129
|
+
let bits = range.prefix;
|
|
130
|
+
for (let i = 0; bits > 0; i++, bits -= 8) {
|
|
131
|
+
const mask = bits >= 8 ? 0xff : (0xff << (8 - bits)) & 0xff;
|
|
132
|
+
if ((range.bytes[i] & mask) !== (address[i] & mask))
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
function range(text) {
|
|
138
|
+
const parsed = parseRange(text);
|
|
139
|
+
if (!parsed)
|
|
140
|
+
throw new Error(`Bad range ${text}`);
|
|
141
|
+
return parsed;
|
|
142
|
+
}
|
|
143
|
+
/** The IPv4 ranges that are not public, with their names (IANA IPv4 Special-Purpose Address Registry). */
|
|
144
|
+
const IPV4_SPECIAL = [
|
|
145
|
+
[range("0.0.0.0/8"), "this-network"],
|
|
146
|
+
[range("10.0.0.0/8"), "private"],
|
|
147
|
+
[range("100.64.0.0/10"), "shared (CGNAT)"],
|
|
148
|
+
[range("127.0.0.0/8"), "loopback"],
|
|
149
|
+
[range("169.254.0.0/16"), "link-local"],
|
|
150
|
+
[range("172.16.0.0/12"), "private"],
|
|
151
|
+
[range("192.0.0.0/24"), "IETF protocol assignment"],
|
|
152
|
+
[range("192.0.2.0/24"), "documentation"],
|
|
153
|
+
[range("192.88.99.0/24"), "6to4 relay"],
|
|
154
|
+
[range("192.168.0.0/16"), "private"],
|
|
155
|
+
[range("198.18.0.0/15"), "benchmarking"],
|
|
156
|
+
[range("198.51.100.0/24"), "documentation"],
|
|
157
|
+
[range("203.0.113.0/24"), "documentation"],
|
|
158
|
+
[range("224.0.0.0/4"), "multicast"],
|
|
159
|
+
[range("240.0.0.0/4"), "reserved"],
|
|
160
|
+
];
|
|
161
|
+
/** The IPv6 ranges in the global unicast range that are not public (IANA IPv6 Special-Purpose Address Registry). */
|
|
162
|
+
const IPV6_SPECIAL = [
|
|
163
|
+
[range("2001::/23"), "IETF protocol assignment"],
|
|
164
|
+
[range("2001:db8::/32"), "documentation"],
|
|
165
|
+
[range("3fff::/20"), "documentation"],
|
|
166
|
+
];
|
|
167
|
+
const GLOBAL_UNICAST = range("2000::/3");
|
|
168
|
+
const IPV4_MAPPED = range("::ffff:0:0/96");
|
|
169
|
+
const NAT64 = range("64:ff9b::/96");
|
|
170
|
+
const SIX_TO_FOUR = range("2002::/16");
|
|
171
|
+
const IPV6_NAMED = [
|
|
172
|
+
[range("::/128"), "unspecified"],
|
|
173
|
+
[range("::1/128"), "loopback"],
|
|
174
|
+
[range("fc00::/7"), "unique local (private)"],
|
|
175
|
+
[range("fe80::/10"), "link-local"],
|
|
176
|
+
[range("fec0::/10"), "site-local"],
|
|
177
|
+
[range("ff00::/8"), "multicast"],
|
|
178
|
+
];
|
|
179
|
+
/**
|
|
180
|
+
* The class of an address that is not public, or undefined for a public address. The class is a
|
|
181
|
+
* name for a message: `loopback`, `private`, `link-local` and the others.
|
|
182
|
+
*/
|
|
183
|
+
export function specialClass(address) {
|
|
184
|
+
if (address.length === 4) {
|
|
185
|
+
for (const [special, name] of IPV4_SPECIAL)
|
|
186
|
+
if (rangeHas(special, address))
|
|
187
|
+
return name;
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
// An IPv6 address that holds an IPv4 address has the class of that address
|
|
191
|
+
if (rangeHas(IPV4_MAPPED, address) || rangeHas(NAT64, address)) {
|
|
192
|
+
const inner = specialClass(address.slice(12, 16));
|
|
193
|
+
return inner === undefined ? undefined : `${inner} (in IPv6)`;
|
|
194
|
+
}
|
|
195
|
+
if (rangeHas(SIX_TO_FOUR, address)) {
|
|
196
|
+
const inner = specialClass(address.slice(2, 6));
|
|
197
|
+
return inner === undefined ? undefined : `${inner} (in 6to4)`;
|
|
198
|
+
}
|
|
199
|
+
for (const [special, name] of IPV6_NAMED)
|
|
200
|
+
if (rangeHas(special, address))
|
|
201
|
+
return name;
|
|
202
|
+
if (!rangeHas(GLOBAL_UNICAST, address))
|
|
203
|
+
return "reserved";
|
|
204
|
+
for (const [special, name] of IPV6_SPECIAL)
|
|
205
|
+
if (rangeHas(special, address))
|
|
206
|
+
return name;
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
/** True for a public address: no special-purpose range has it. */
|
|
210
|
+
export function isPublicAddress(address) {
|
|
211
|
+
const bytes = typeof address === "string" ? parseAddress(address) : address;
|
|
212
|
+
return bytes !== undefined && specialClass(bytes) === undefined;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAKhC,oEAAoE;AACpE,SAAS,SA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AK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QAClD,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,YAAY,CAAC;IAChE,CAAC;IACD,IAAI,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAChD,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,YAAY,CAAC;IAChE,CAAC;IACD,KAAK,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,UAAU;QAAE,IAAI,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;IACtF,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;QAAE,OAAO,UAAU,CAAC;IAC1D,KAAK,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,YAAY;QAAE,IAAI,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;IACxF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,eAAe,CAAC,OAA8B;IAC5D,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC5E,OAAO,KAAK,KAAK,SAAS,IAAI,YAAY,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC;AAClE,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The errors of the HTTP procedures that are not a refusal or a stop. A server sends them with
|
|
3
|
+
* the code `HANDLER_ERROR` and the message. `code` tells the kind to a caller in the process.
|
|
4
|
+
*/
|
|
5
|
+
/** The kinds of `HttpError`. */
|
|
6
|
+
export type HttpErrorCode =
|
|
7
|
+
/** The URL is not an `http:` or `https:` URL. */
|
|
8
|
+
"BAD_URL"
|
|
9
|
+
/** The body of the request is larger than the limit of the module. */
|
|
10
|
+
| "REQUEST_TOO_LARGE"
|
|
11
|
+
/** The body of the response is larger than `maxResponseBytes`. */
|
|
12
|
+
| "RESPONSE_TOO_LARGE"
|
|
13
|
+
/** One NDJSON line is larger than `maxLineBytes`. */
|
|
14
|
+
| "LINE_TOO_LARGE"
|
|
15
|
+
/** One server-sent event is larger than `maxEventBytes`. */
|
|
16
|
+
| "EVENT_TOO_LARGE"
|
|
17
|
+
/** The redirects are more than `maxRedirects`. */
|
|
18
|
+
| "TOO_MANY_REDIRECTS"
|
|
19
|
+
/** The response is a redirect, and the input has `redirect: "error"`. */
|
|
20
|
+
| "REDIRECT"
|
|
21
|
+
/** The status of the response is not in 200 to 299 (`http.json`, `http.ndjson`, `http.sse`). */
|
|
22
|
+
| "HTTP_STATUS"
|
|
23
|
+
/** The body is not JSON, or a line of NDJSON is not JSON. */
|
|
24
|
+
| "BAD_JSON"
|
|
25
|
+
/** The content type of an event stream is not `text/event-stream`. */
|
|
26
|
+
| "BAD_CONTENT_TYPE"
|
|
27
|
+
/** The connection failed: no answer, a reset, a TLS error. */
|
|
28
|
+
| "CONNECTION";
|
|
29
|
+
/** An error of an HTTP procedure. */
|
|
30
|
+
export declare class HttpError extends Error {
|
|
31
|
+
readonly code: HttpErrorCode;
|
|
32
|
+
/** The status of the response, when the server answered. */
|
|
33
|
+
readonly status?: number | undefined;
|
|
34
|
+
readonly name = "HttpError";
|
|
35
|
+
constructor(code: HttpErrorCode, message: string,
|
|
36
|
+
/** The status of the response, when the server answered. */
|
|
37
|
+
status?: number | undefined, options?: ErrorOptions);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,gCAAgC;AAChC,MAAM,MAAM,aAAa;AACvB,iDAAiD;AAC/C,SAAS;AACX,sEAAsE;GACpE,mBAAmB;AACrB,kEAAkE;GAChE,oBAAoB;AACtB,qDAAqD;GACnD,gBAAgB;AAClB,4DAA4D;GAC1D,iBAAiB;AACnB,kDAAkD;GAChD,oBAAoB;AACtB,yEAAyE;GACvE,UAAU;AACZ,gGAAgG;GAC9F,aAAa;AACf,6DAA6D;GAC3D,UAAU;AACZ,sEAAsE;GACpE,kBAAkB;AACpB,8DAA8D;GAC5D,YAAY,CAAC;AAEjB,qCAAqC;AACrC,qBAAa,SAAU,SAAQ,KAAK;IAIhC,QAAQ,CAAC,IAAI,EAAE,aAAa;IAE5B,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAN1B,SAAkB,IAAI,eAAe;IAErC,YACW,IAAI,EAAE,aAAa,EAC5B,OAAO,EAAE,MAAM;IACf,4DAA4D;IACnD,MAAM,CAAC,EAAE,MAAM,YAAA,EACxB,OAAO,CAAC,EAAE,YAAY,EAGvB;CACF"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The errors of the HTTP procedures that are not a refusal or a stop. A server sends them with
|
|
3
|
+
* the code `HANDLER_ERROR` and the message. `code` tells the kind to a caller in the process.
|
|
4
|
+
*/
|
|
5
|
+
/** An error of an HTTP procedure. */
|
|
6
|
+
export class HttpError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
status;
|
|
9
|
+
name = "HttpError";
|
|
10
|
+
constructor(code, message,
|
|
11
|
+
/** The status of the response, when the server answered. */
|
|
12
|
+
status, options) {
|
|
13
|
+
super(message, options);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.status = status;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2BH,qCAAqC;AACrC,MAAM,OAAO,SAAU,SAAQ,KAAK;IAIvB,IAAI;IAGJ,MAAM;IANC,IAAI,GAAG,WAAW,CAAC;IAErC,YACW,IAAmB,EAC5B,OAAe;IACf,4DAA4D;IACnD,MAAe,EACxB,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;oBANf,IAAI;sBAGJ,MAAM;IAIjB,CAAC;CACF"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One HTTP exchange with the host check, the redirects and the limits (roadmap R38).
|
|
3
|
+
*
|
|
4
|
+
* The exchange uses `node:http` and `node:https`, not `fetch`: the connection must use the
|
|
5
|
+
* addresses that the host check allowed. A `lookup` function gives those addresses to the socket,
|
|
6
|
+
* so the DNS cannot give another address after the check (DNS rebinding). The exchange follows
|
|
7
|
+
* each redirect itself and examines each new host. Each request gets its own connection.
|
|
8
|
+
*/
|
|
9
|
+
import { type IncomingHttpHeaders, type IncomingMessage } from "node:http";
|
|
10
|
+
import { type Readable } from "node:stream";
|
|
11
|
+
import type { ProcedurePath } from "@procedures/client";
|
|
12
|
+
import { HttpError } from "./errors.js";
|
|
13
|
+
import { type HostPolicy } from "./policy.js";
|
|
14
|
+
import type { CallScope } from "./scope.js";
|
|
15
|
+
/** One mebibyte. */
|
|
16
|
+
export declare const MIB: number;
|
|
17
|
+
/** The default size limit of a response body and of a request body: 10 MiB. */
|
|
18
|
+
export declare const DEFAULT_MAX_BYTES: number;
|
|
19
|
+
/** The default size limit of one NDJSON line and of one server-sent event: 1 MiB. */
|
|
20
|
+
export declare const DEFAULT_ITEM_BYTES: number;
|
|
21
|
+
/** The default time of `http.request` and `http.json`: 30 seconds. */
|
|
22
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
23
|
+
/** The default number of redirects that a call follows. */
|
|
24
|
+
export declare const DEFAULT_MAX_REDIRECTS = 5;
|
|
25
|
+
/** The settings of a module: the host policy and the size limits of the host. */
|
|
26
|
+
export interface HttpSettings {
|
|
27
|
+
readonly policy: HostPolicy;
|
|
28
|
+
/** The largest body of a request, in bytes. */
|
|
29
|
+
readonly maxRequestBytes: number;
|
|
30
|
+
/** The largest body of a response, in bytes. An input can set a smaller limit. */
|
|
31
|
+
readonly maxResponseBytes: number;
|
|
32
|
+
}
|
|
33
|
+
/** The settings of the default module: each public host, and 10 MiB for each body. */
|
|
34
|
+
export declare const DEFAULT_SETTINGS: HttpSettings;
|
|
35
|
+
/** What to do with a redirect. */
|
|
36
|
+
export type RedirectMode = "follow" | "manual" | "error";
|
|
37
|
+
/** A request before the first exchange. */
|
|
38
|
+
export interface PreparedRequest {
|
|
39
|
+
readonly url: URL;
|
|
40
|
+
readonly method: string;
|
|
41
|
+
/** The headers, with names in lowercase. */
|
|
42
|
+
readonly headers: Record<string, string>;
|
|
43
|
+
readonly body?: Buffer | undefined;
|
|
44
|
+
readonly redirect: RedirectMode;
|
|
45
|
+
readonly maxRedirects: number;
|
|
46
|
+
}
|
|
47
|
+
/** The parts of a request that the procedures share. */
|
|
48
|
+
export interface RequestParts {
|
|
49
|
+
readonly url: string;
|
|
50
|
+
readonly method?: string | undefined;
|
|
51
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
52
|
+
readonly query?: Readonly<Record<string, QueryValue | readonly QueryValue[]>> | undefined;
|
|
53
|
+
readonly redirect?: RedirectMode | undefined;
|
|
54
|
+
readonly maxRedirects?: number | undefined;
|
|
55
|
+
}
|
|
56
|
+
/** A value of the query of a URL. */
|
|
57
|
+
export type QueryValue = string | number | boolean;
|
|
58
|
+
/** The response of an exchange. */
|
|
59
|
+
export interface Exchange {
|
|
60
|
+
readonly response: IncomingMessage;
|
|
61
|
+
/** The body without its content encoding (gzip, deflate or br). */
|
|
62
|
+
readonly body: Readable;
|
|
63
|
+
/** The URL of the response: the last URL after the redirects. */
|
|
64
|
+
readonly url: string;
|
|
65
|
+
/** The URLs of the redirects that the exchange followed. */
|
|
66
|
+
readonly redirects: readonly string[];
|
|
67
|
+
/** This function closes the connection. */
|
|
68
|
+
close(): void;
|
|
69
|
+
}
|
|
70
|
+
/** This function parses the URL of an input, and adds the query. Only `http:` and `https:` pass. */
|
|
71
|
+
export declare function urlOf(parts: RequestParts, path: ProcedurePath): URL;
|
|
72
|
+
/** The headers of an input with names in lowercase. A later name of the same header wins. */
|
|
73
|
+
export declare function headersOf(headers: Readonly<Record<string, string>> | undefined, defaults?: Readonly<Record<string, string>>): Record<string, string>;
|
|
74
|
+
/** This function makes a request from the shared parts of an input. */
|
|
75
|
+
export declare function prepare(parts: RequestParts, path: ProcedurePath, settings: HttpSettings, extra?: {
|
|
76
|
+
headers?: Record<string, string>;
|
|
77
|
+
body?: Buffer | undefined;
|
|
78
|
+
}): PreparedRequest;
|
|
79
|
+
/** The text of a header value: several values are joined with a comma. */
|
|
80
|
+
export declare function headerText(value: string | string[] | undefined): string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* This function sends a request, follows the redirects and gives the response. Each URL goes
|
|
83
|
+
* through the host check before its connection. A refused host throws `FORBIDDEN` with the
|
|
84
|
+
* reason `host-not-allowed`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function exchange(request: PreparedRequest, policy: HostPolicy, scope: CallScope): Promise<Exchange>;
|
|
87
|
+
/** This function reads a whole body. More than `maxBytes` bytes throws `RESPONSE_TOO_LARGE`. */
|
|
88
|
+
export declare function readBody(body: Readable, maxBytes: number, scope: CallScope, response: IncomingMessage): Promise<Buffer>;
|
|
89
|
+
/** The headers of a response as JSON: a string, or a list for `set-cookie`. */
|
|
90
|
+
export declare function responseHeaders(headers: IncomingHttpHeaders): Record<string, string | string[]>;
|
|
91
|
+
/** The first characters of a body, for a message. */
|
|
92
|
+
export declare function excerpt(body: Buffer | string, length?: number): string;
|
|
93
|
+
/** True for a status in 200 to 299. */
|
|
94
|
+
export declare function isOk(status: number): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* The `HTTP_STATUS` error of a response whose status is not in 200 to 299. The message has the
|
|
97
|
+
* start of the body (at most 4 KiB is read).
|
|
98
|
+
*/
|
|
99
|
+
export declare function statusError(opened: Exchange, scope: CallScope): Promise<HttpError>;
|
|
100
|
+
/** The chunks of a body. Each chunk starts the idle time of the scope again. */
|
|
101
|
+
export declare function touching(body: Readable, scope: CallScope): AsyncGenerator<Uint8Array | string, void, undefined>;
|
|
102
|
+
//# sourceMappingURL=exchange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exchange.d.ts","sourceRoot":"","sources":["../src/exchange.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA2B,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAuB,MAAM,WAAW,CAAC;AAGzH,OAAO,EAAyB,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAsD,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,oBAAoB;AACpB,eAAO,MAAM,GAAG,EAAE,MAAoB,CAAC;AAEvC,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,EAAE,MAAiB,CAAC;AAElD,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,EAAE,MAAY,CAAC;AAE9C,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,QAAS,CAAC;AAEzC,2DAA2D;AAC3D,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAA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