@npy/fetch 0.1.0 → 0.1.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/_internal/consts.cjs +4 -0
- package/_internal/consts.d.cts +3 -0
- package/_internal/consts.d.ts +3 -0
- package/_internal/consts.js +4 -0
- package/_internal/decode-stream-error.cjs +18 -0
- package/_internal/decode-stream-error.d.cts +11 -0
- package/_internal/decode-stream-error.d.ts +11 -0
- package/_internal/decode-stream-error.js +18 -0
- package/_internal/error-mapping.cjs +44 -0
- package/_internal/error-mapping.d.cts +15 -0
- package/_internal/error-mapping.d.ts +15 -0
- package/_internal/error-mapping.js +41 -0
- package/_internal/guards.cjs +23 -0
- package/_internal/guards.d.cts +15 -0
- package/_internal/guards.d.ts +15 -0
- package/_internal/guards.js +15 -0
- package/_internal/net.cjs +95 -0
- package/_internal/net.d.cts +11 -0
- package/_internal/net.d.ts +11 -0
- package/_internal/net.js +92 -0
- package/_internal/promises.cjs +18 -0
- package/_internal/promises.d.cts +1 -0
- package/_internal/promises.d.ts +1 -0
- package/_internal/promises.js +18 -0
- package/_internal/streams.cjs +37 -0
- package/_internal/streams.d.cts +21 -0
- package/_internal/streams.d.ts +21 -0
- package/_internal/streams.js +36 -0
- package/_internal/symbols.cjs +4 -0
- package/_internal/symbols.d.cts +1 -0
- package/_internal/symbols.d.ts +1 -0
- package/_internal/symbols.js +4 -0
- package/_virtual/_rolldown/runtime.cjs +23 -0
- package/agent-pool.cjs +96 -0
- package/agent-pool.d.cts +2 -0
- package/agent-pool.d.ts +2 -0
- package/agent-pool.js +95 -0
- package/agent.cjs +260 -0
- package/agent.d.cts +3 -0
- package/agent.d.ts +3 -0
- package/agent.js +259 -0
- package/body.cjs +105 -0
- package/body.d.cts +12 -0
- package/body.d.ts +12 -0
- package/body.js +102 -0
- package/dialers/index.d.cts +3 -0
- package/dialers/index.d.ts +3 -0
- package/dialers/proxy.cjs +56 -0
- package/dialers/proxy.d.cts +27 -0
- package/dialers/proxy.d.ts +27 -0
- package/dialers/proxy.js +55 -0
- package/dialers/tcp.cjs +92 -0
- package/dialers/tcp.d.cts +57 -0
- package/dialers/tcp.d.ts +57 -0
- package/dialers/tcp.js +89 -0
- package/encoding.cjs +114 -0
- package/encoding.d.cts +35 -0
- package/encoding.d.ts +35 -0
- package/encoding.js +110 -0
- package/errors.cjs +275 -0
- package/errors.d.cts +110 -0
- package/errors.d.ts +110 -0
- package/errors.js +259 -0
- package/fetch.cjs +353 -0
- package/fetch.d.cts +58 -0
- package/fetch.d.ts +58 -0
- package/fetch.js +350 -0
- package/http-client.cjs +75 -0
- package/http-client.d.cts +39 -0
- package/http-client.d.ts +39 -0
- package/http-client.js +75 -0
- package/index.cjs +49 -0
- package/index.d.cts +14 -0
- package/index.d.ts +14 -0
- package/index.js +11 -0
- package/io/_utils.cjs +56 -0
- package/io/_utils.d.cts +10 -0
- package/io/_utils.d.ts +10 -0
- package/io/_utils.js +51 -0
- package/io/buf-writer.cjs +149 -0
- package/io/buf-writer.d.cts +13 -0
- package/io/buf-writer.d.ts +13 -0
- package/io/buf-writer.js +148 -0
- package/io/io.cjs +199 -0
- package/io/io.d.cts +5 -0
- package/io/io.d.ts +5 -0
- package/io/io.js +198 -0
- package/io/readers.cjs +337 -0
- package/io/readers.d.cts +69 -0
- package/io/readers.d.ts +69 -0
- package/io/readers.js +333 -0
- package/io/writers.cjs +196 -0
- package/io/writers.d.cts +22 -0
- package/io/writers.d.ts +22 -0
- package/io/writers.js +195 -0
- package/package.json +23 -10
- package/types/agent.d.cts +72 -0
- package/types/agent.d.ts +72 -0
- package/types/dialer.d.cts +30 -0
- package/types/dialer.d.ts +30 -0
- package/types/index.d.cts +2 -0
- package/types/index.d.ts +2 -0
package/io/writers.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { bytesToStream } from "../_internal/streams.js";
|
|
2
|
+
import { createEncoders, encodeStream } from "../encoding.js";
|
|
3
|
+
import { parseContentLength, parseTransferEncoding } from "./_utils.js";
|
|
4
|
+
import { sanitizeHeaderValue } from "./readers.js";
|
|
5
|
+
import { isFumanReadable, isReadableStream } from "../_internal/guards.js";
|
|
6
|
+
import { extractBody } from "../body.js";
|
|
7
|
+
import { BufWriter } from "./buf-writer.js";
|
|
8
|
+
import { nodeReadableToWeb } from "@fuman/node";
|
|
9
|
+
import { Bytes, fumanReadableToWeb, write } from "@fuman/io";
|
|
10
|
+
//#region src/io/writers.ts
|
|
11
|
+
function toRequestTarget(url) {
|
|
12
|
+
return (url.pathname?.startsWith("/") ? url.pathname : "/") + (url.search || "");
|
|
13
|
+
}
|
|
14
|
+
function encodeHead(into, head) {
|
|
15
|
+
write.rawString(into, `${head.method.toUpperCase()} ${head.target} HTTP/1.1\r
|
|
16
|
+
`);
|
|
17
|
+
for (const [k, v] of head.headers) write.rawString(into, `${k}: ${sanitizeHeaderValue(v)}\r
|
|
18
|
+
`);
|
|
19
|
+
write.rawString(into, "\r\n");
|
|
20
|
+
}
|
|
21
|
+
function prepareBody(headers, init) {
|
|
22
|
+
const state = extractBody(init);
|
|
23
|
+
if (state.body != null && !headers.has("content-type")) headers.set("content-type", state.contentType ?? "application/octet-stream");
|
|
24
|
+
const body = state.body;
|
|
25
|
+
if (body == null) return { kind: "none" };
|
|
26
|
+
if (body instanceof Uint8Array) return {
|
|
27
|
+
kind: "bytes",
|
|
28
|
+
bytes: body,
|
|
29
|
+
length: body.byteLength
|
|
30
|
+
};
|
|
31
|
+
if (isReadableStream(body)) return {
|
|
32
|
+
kind: "stream",
|
|
33
|
+
stream: body,
|
|
34
|
+
length: state.contentLength
|
|
35
|
+
};
|
|
36
|
+
if (isFumanReadable(body)) return {
|
|
37
|
+
kind: "stream",
|
|
38
|
+
stream: fumanReadableToWeb(body),
|
|
39
|
+
length: state.contentLength
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
kind: "stream",
|
|
43
|
+
stream: nodeReadableToWeb(body),
|
|
44
|
+
length: state.contentLength
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function finalizeDelimitation(headers, body) {
|
|
48
|
+
if (body.kind === "none") return { chunked: false };
|
|
49
|
+
const te = parseTransferEncoding(headers);
|
|
50
|
+
if (te.has) {
|
|
51
|
+
headers.delete("content-length");
|
|
52
|
+
if (!te.chunked) {
|
|
53
|
+
const tokens = [...te.codings, "chunked"].filter(Boolean);
|
|
54
|
+
headers.set("transfer-encoding", tokens.join(", "));
|
|
55
|
+
}
|
|
56
|
+
return { chunked: true };
|
|
57
|
+
}
|
|
58
|
+
const knownLength = body.kind === "bytes" ? body.length : body.length ?? null;
|
|
59
|
+
if (knownLength != null) {
|
|
60
|
+
const existing = parseContentLength(headers);
|
|
61
|
+
if (existing != null && existing !== knownLength) throw new Error(`Conflicting content-length: header=${existing} body=${knownLength}`);
|
|
62
|
+
if (existing == null) headers.set("content-length", String(knownLength));
|
|
63
|
+
return { chunked: false };
|
|
64
|
+
}
|
|
65
|
+
if (parseContentLength(headers) != null) return { chunked: false };
|
|
66
|
+
headers.set("transfer-encoding", "chunked");
|
|
67
|
+
headers.delete("content-length");
|
|
68
|
+
return { chunked: true };
|
|
69
|
+
}
|
|
70
|
+
function createBufferedConnWriter(dst, opts) {
|
|
71
|
+
const bufferSize = opts.writeBufferSize ?? 16 * 1024;
|
|
72
|
+
const directWriteThreshold = opts.directWriteThreshold ?? 64 * 1024;
|
|
73
|
+
const bufWriter = new BufWriter(dst, bufferSize);
|
|
74
|
+
const flush = async () => {
|
|
75
|
+
await bufWriter.flush();
|
|
76
|
+
};
|
|
77
|
+
const writeBytes = async (bytes) => {
|
|
78
|
+
if (bytes.length === 0) return;
|
|
79
|
+
if (bytes.length >= directWriteThreshold) {
|
|
80
|
+
await bufWriter.flush();
|
|
81
|
+
await dst.write(bytes);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
await bufWriter.write(bytes);
|
|
85
|
+
};
|
|
86
|
+
const writeRawString = async (str) => {
|
|
87
|
+
if (str.length === 0) return;
|
|
88
|
+
write.rawString(bufWriter, str);
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
flush,
|
|
92
|
+
writeBytes,
|
|
93
|
+
writeRawString,
|
|
94
|
+
directWriteThreshold
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async function writeBody(dst, body, chunked, opts, signal) {
|
|
98
|
+
const bw = createBufferedConnWriter(dst, opts);
|
|
99
|
+
const writeChunk = async (chunk) => {
|
|
100
|
+
if (signal?.aborted) throw signal.reason ?? /* @__PURE__ */ new Error("Request aborted");
|
|
101
|
+
if (!chunked) {
|
|
102
|
+
await bw.writeBytes(chunk);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (chunk.length === 0) return;
|
|
106
|
+
await bw.writeRawString(chunk.length.toString(16));
|
|
107
|
+
await bw.writeRawString("\r\n");
|
|
108
|
+
await bw.writeBytes(chunk);
|
|
109
|
+
await bw.writeRawString("\r\n");
|
|
110
|
+
};
|
|
111
|
+
if (body.kind === "bytes") await writeChunk(body.bytes);
|
|
112
|
+
else for await (const chunk of body.stream) await writeChunk(chunk);
|
|
113
|
+
if (chunked) await bw.writeRawString(`0\r
|
|
114
|
+
\r
|
|
115
|
+
`);
|
|
116
|
+
await bw.flush();
|
|
117
|
+
}
|
|
118
|
+
async function writeCoalesced(dst, scratch, head, bodyBytes, chunked) {
|
|
119
|
+
scratch.reset();
|
|
120
|
+
encodeHead(scratch, head);
|
|
121
|
+
if (!chunked) {
|
|
122
|
+
write.bytes(scratch, bodyBytes);
|
|
123
|
+
await dst.write(scratch.result());
|
|
124
|
+
scratch.reset();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
write.rawString(scratch, bodyBytes.length.toString(16));
|
|
128
|
+
write.rawString(scratch, "\r\n");
|
|
129
|
+
write.bytes(scratch, bodyBytes);
|
|
130
|
+
write.rawString(scratch, `\r
|
|
131
|
+
0\r
|
|
132
|
+
\r
|
|
133
|
+
`);
|
|
134
|
+
await dst.write(scratch.result());
|
|
135
|
+
scratch.reset();
|
|
136
|
+
}
|
|
137
|
+
function createRequestWriter(dst, opts = {}) {
|
|
138
|
+
const scratch = Bytes.alloc(opts.writeBufferSize ?? 16 * 1024);
|
|
139
|
+
const write = async (req) => {
|
|
140
|
+
if (req.signal?.aborted) throw req.signal.reason ?? /* @__PURE__ */ new Error("Request aborted");
|
|
141
|
+
const method = req.method.toUpperCase();
|
|
142
|
+
const headers = req.headers ? new Headers(req.headers) : new Headers();
|
|
143
|
+
const url = req.url;
|
|
144
|
+
if (!headers.has("host")) headers.set("host", url.host);
|
|
145
|
+
if (!headers.has("date")) headers.set("date", (/* @__PURE__ */ new Date()).toUTCString());
|
|
146
|
+
const target = toRequestTarget(url);
|
|
147
|
+
let body = prepareBody(headers, req.body ?? null);
|
|
148
|
+
const ceRaw = headers.get("content-encoding") ?? void 0;
|
|
149
|
+
const ceEncoders = createEncoders(ceRaw);
|
|
150
|
+
if (body.kind !== "none" && ceEncoders.length > 0) {
|
|
151
|
+
body = {
|
|
152
|
+
kind: "stream",
|
|
153
|
+
stream: encodeStream(body.kind === "stream" ? body.stream : bytesToStream(body.bytes), ceRaw),
|
|
154
|
+
length: null
|
|
155
|
+
};
|
|
156
|
+
headers.delete("content-length");
|
|
157
|
+
}
|
|
158
|
+
const teInfo = parseTransferEncoding(headers);
|
|
159
|
+
if (body.kind !== "none" && teInfo.has && teInfo.codings.length > 0) {
|
|
160
|
+
body = {
|
|
161
|
+
kind: "stream",
|
|
162
|
+
stream: encodeStream(body.kind === "stream" ? body.stream : bytesToStream(body.bytes), teInfo.codings),
|
|
163
|
+
length: null
|
|
164
|
+
};
|
|
165
|
+
headers.delete("content-length");
|
|
166
|
+
}
|
|
167
|
+
const { chunked } = finalizeDelimitation(headers, body);
|
|
168
|
+
const head = {
|
|
169
|
+
method,
|
|
170
|
+
target,
|
|
171
|
+
headers
|
|
172
|
+
};
|
|
173
|
+
if (body.kind === "bytes") {
|
|
174
|
+
const max = opts.coalesceBodyMaxBytes ?? 64 * 1024;
|
|
175
|
+
if (body.bytes.length <= max) {
|
|
176
|
+
await writeCoalesced(dst, scratch, head, body.bytes, chunked);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
scratch.reset();
|
|
181
|
+
encodeHead(scratch, head);
|
|
182
|
+
await dst.write(scratch.result());
|
|
183
|
+
scratch.reset();
|
|
184
|
+
if (body.kind === "none") return;
|
|
185
|
+
if (body.kind === "bytes" && !chunked) {
|
|
186
|
+
if (req.signal?.aborted) throw req.signal.reason ?? /* @__PURE__ */ new Error("Request aborted");
|
|
187
|
+
await dst.write(body.bytes);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
await writeBody(dst, body, chunked, opts, req.signal);
|
|
191
|
+
};
|
|
192
|
+
return { write };
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { createRequestWriter };
|
package/package.json
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npy/fetch",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
|
+
"description": "HTTP/1.1 client built from raw TCP sockets with fetch-compatible primitives and proxy support.",
|
|
5
6
|
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"fetch",
|
|
9
|
+
"http",
|
|
10
|
+
"http-client",
|
|
11
|
+
"proxy",
|
|
12
|
+
"socks",
|
|
13
|
+
"socks5",
|
|
14
|
+
"tcp",
|
|
15
|
+
"node",
|
|
16
|
+
"bun"
|
|
17
|
+
],
|
|
6
18
|
"scripts": {},
|
|
7
19
|
"dependencies": {
|
|
8
20
|
"@fuman/io": "^0.0.19",
|
|
9
21
|
"@fuman/net": "^0.0.19",
|
|
10
22
|
"@fuman/node": "^0.0.19",
|
|
11
23
|
"@fuman/utils": "^0.0.19",
|
|
12
|
-
"@npy/proxy-kit": "0.1.
|
|
24
|
+
"@npy/proxy-kit": "0.1.2",
|
|
13
25
|
"bytes": "^3.1.2",
|
|
14
|
-
"generic-pool": "^3.9.0"
|
|
15
|
-
"mitata": "^1.0.34"
|
|
26
|
+
"generic-pool": "^3.9.0"
|
|
16
27
|
},
|
|
17
28
|
"exports": {
|
|
18
29
|
".": {
|
|
@@ -27,13 +38,15 @@
|
|
|
27
38
|
}
|
|
28
39
|
},
|
|
29
40
|
"sideEffects": false,
|
|
30
|
-
"
|
|
31
|
-
"dist",
|
|
32
|
-
"LICENSE",
|
|
33
|
-
"README.md"
|
|
34
|
-
],
|
|
41
|
+
"homepage": "https://github.com/neeopy/npy",
|
|
35
42
|
"repository": {
|
|
36
43
|
"type": "git",
|
|
37
44
|
"url": "git+https://github.com/neeopy/npy.git"
|
|
38
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/neeopy/npy/issues"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"**/*"
|
|
51
|
+
]
|
|
39
52
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BodyInit } from '../body';
|
|
2
|
+
import { LineReader, Readers } from '../io/readers';
|
|
3
|
+
import { Writers } from '../io/writers';
|
|
4
|
+
import { Dialer } from './dialer';
|
|
5
|
+
export interface Agent {
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
close(): void;
|
|
8
|
+
readonly hostname: string;
|
|
9
|
+
readonly port: number;
|
|
10
|
+
/**
|
|
11
|
+
* Sends a single HTTP request and returns the raw {@link Response}.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* The returned response body preserves the advanced error mapping of this library.
|
|
15
|
+
* Limits configured through reader options are enforced while the body is consumed.
|
|
16
|
+
*/
|
|
17
|
+
send(options: Agent.SendOptions): Promise<Response>;
|
|
18
|
+
whenIdle(): Promise<void>;
|
|
19
|
+
readonly isIdle: boolean;
|
|
20
|
+
readonly lastUsed: number;
|
|
21
|
+
}
|
|
22
|
+
export declare namespace Agent {
|
|
23
|
+
interface ConnectOptions {
|
|
24
|
+
timeout?: number;
|
|
25
|
+
keepAlive?: boolean | null;
|
|
26
|
+
noDelay?: boolean;
|
|
27
|
+
}
|
|
28
|
+
type ReaderOptions = Readers.Options & LineReader.ReadHeadersOptions;
|
|
29
|
+
type WriterOptions = Writers.Options;
|
|
30
|
+
interface IOOptions {
|
|
31
|
+
reader?: ReaderOptions;
|
|
32
|
+
writer?: WriterOptions;
|
|
33
|
+
}
|
|
34
|
+
interface Options {
|
|
35
|
+
connect?: ConnectOptions;
|
|
36
|
+
io?: IOOptions;
|
|
37
|
+
}
|
|
38
|
+
interface SendOptions {
|
|
39
|
+
url: string | URL;
|
|
40
|
+
method: string;
|
|
41
|
+
headers?: Headers;
|
|
42
|
+
body?: BodyInit | null;
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export interface AgentPool {
|
|
47
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
readonly hostname: string;
|
|
50
|
+
readonly port: number;
|
|
51
|
+
send(options: Agent.SendOptions): Promise<Response>;
|
|
52
|
+
}
|
|
53
|
+
export declare namespace AgentPool {
|
|
54
|
+
interface Options {
|
|
55
|
+
dialer?: Dialer;
|
|
56
|
+
poolMaxIdlePerHost?: number;
|
|
57
|
+
poolMaxPerHost?: number;
|
|
58
|
+
poolIdleTimeout?: number | false;
|
|
59
|
+
connect?: Agent.ConnectOptions;
|
|
60
|
+
io?: Agent.IOOptions;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export interface AgentConnectOptions extends Agent.ConnectOptions {
|
|
64
|
+
}
|
|
65
|
+
export interface AgentPoolOptions extends AgentPool.Options {
|
|
66
|
+
}
|
|
67
|
+
export interface SendOptions extends Agent.SendOptions {
|
|
68
|
+
}
|
|
69
|
+
export interface AgentIOOptions extends Agent.IOOptions {
|
|
70
|
+
}
|
|
71
|
+
export type AgentReaderOptions = Agent.ReaderOptions;
|
|
72
|
+
export type AgentWriterOptions = Agent.WriterOptions;
|
package/types/agent.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BodyInit } from '../body';
|
|
2
|
+
import { LineReader, Readers } from '../io/readers';
|
|
3
|
+
import { Writers } from '../io/writers';
|
|
4
|
+
import { Dialer } from './dialer';
|
|
5
|
+
export interface Agent {
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
close(): void;
|
|
8
|
+
readonly hostname: string;
|
|
9
|
+
readonly port: number;
|
|
10
|
+
/**
|
|
11
|
+
* Sends a single HTTP request and returns the raw {@link Response}.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* The returned response body preserves the advanced error mapping of this library.
|
|
15
|
+
* Limits configured through reader options are enforced while the body is consumed.
|
|
16
|
+
*/
|
|
17
|
+
send(options: Agent.SendOptions): Promise<Response>;
|
|
18
|
+
whenIdle(): Promise<void>;
|
|
19
|
+
readonly isIdle: boolean;
|
|
20
|
+
readonly lastUsed: number;
|
|
21
|
+
}
|
|
22
|
+
export declare namespace Agent {
|
|
23
|
+
interface ConnectOptions {
|
|
24
|
+
timeout?: number;
|
|
25
|
+
keepAlive?: boolean | null;
|
|
26
|
+
noDelay?: boolean;
|
|
27
|
+
}
|
|
28
|
+
type ReaderOptions = Readers.Options & LineReader.ReadHeadersOptions;
|
|
29
|
+
type WriterOptions = Writers.Options;
|
|
30
|
+
interface IOOptions {
|
|
31
|
+
reader?: ReaderOptions;
|
|
32
|
+
writer?: WriterOptions;
|
|
33
|
+
}
|
|
34
|
+
interface Options {
|
|
35
|
+
connect?: ConnectOptions;
|
|
36
|
+
io?: IOOptions;
|
|
37
|
+
}
|
|
38
|
+
interface SendOptions {
|
|
39
|
+
url: string | URL;
|
|
40
|
+
method: string;
|
|
41
|
+
headers?: Headers;
|
|
42
|
+
body?: BodyInit | null;
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export interface AgentPool {
|
|
47
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
readonly hostname: string;
|
|
50
|
+
readonly port: number;
|
|
51
|
+
send(options: Agent.SendOptions): Promise<Response>;
|
|
52
|
+
}
|
|
53
|
+
export declare namespace AgentPool {
|
|
54
|
+
interface Options {
|
|
55
|
+
dialer?: Dialer;
|
|
56
|
+
poolMaxIdlePerHost?: number;
|
|
57
|
+
poolMaxPerHost?: number;
|
|
58
|
+
poolIdleTimeout?: number | false;
|
|
59
|
+
connect?: Agent.ConnectOptions;
|
|
60
|
+
io?: Agent.IOOptions;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export interface AgentConnectOptions extends Agent.ConnectOptions {
|
|
64
|
+
}
|
|
65
|
+
export interface AgentPoolOptions extends AgentPool.Options {
|
|
66
|
+
}
|
|
67
|
+
export interface SendOptions extends Agent.SendOptions {
|
|
68
|
+
}
|
|
69
|
+
export interface AgentIOOptions extends Agent.IOOptions {
|
|
70
|
+
}
|
|
71
|
+
export type AgentReaderOptions = Agent.ReaderOptions;
|
|
72
|
+
export type AgentWriterOptions = Agent.WriterOptions;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ITcpConnection, ITlsConnection } from '@fuman/net';
|
|
2
|
+
import { NodeTlsConnectOptions } from '@fuman/node';
|
|
3
|
+
/**
|
|
4
|
+
* Transport abstraction responsible for opening a connection to an HTTP target.
|
|
5
|
+
*/
|
|
6
|
+
export interface Dialer {
|
|
7
|
+
dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
|
|
8
|
+
}
|
|
9
|
+
export declare namespace Dialer {
|
|
10
|
+
type ConnectionLike = ITcpConnection | ITlsConnection;
|
|
11
|
+
interface Target {
|
|
12
|
+
address: string;
|
|
13
|
+
port: number;
|
|
14
|
+
secure: boolean;
|
|
15
|
+
/** Server Name Indication (TLS). Defaults to the host when applicable. */
|
|
16
|
+
sni?: string;
|
|
17
|
+
/** Defaults to ["http/1.1"] when omitted by the dialer implementation. */
|
|
18
|
+
alpnProtocols?: string[];
|
|
19
|
+
/** Extra Node.js TLS options (minVersion, servername, etc.). */
|
|
20
|
+
extraOptions?: NodeTlsConnectOptions["extraOptions"];
|
|
21
|
+
}
|
|
22
|
+
interface Options {
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Back-compat */
|
|
27
|
+
export type ConnectionLike = Dialer.ConnectionLike;
|
|
28
|
+
/** Back-compat */
|
|
29
|
+
export interface DialTarget extends Dialer.Target {
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ITcpConnection, ITlsConnection } from '@fuman/net';
|
|
2
|
+
import { NodeTlsConnectOptions } from '@fuman/node';
|
|
3
|
+
/**
|
|
4
|
+
* Transport abstraction responsible for opening a connection to an HTTP target.
|
|
5
|
+
*/
|
|
6
|
+
export interface Dialer {
|
|
7
|
+
dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
|
|
8
|
+
}
|
|
9
|
+
export declare namespace Dialer {
|
|
10
|
+
type ConnectionLike = ITcpConnection | ITlsConnection;
|
|
11
|
+
interface Target {
|
|
12
|
+
address: string;
|
|
13
|
+
port: number;
|
|
14
|
+
secure: boolean;
|
|
15
|
+
/** Server Name Indication (TLS). Defaults to the host when applicable. */
|
|
16
|
+
sni?: string;
|
|
17
|
+
/** Defaults to ["http/1.1"] when omitted by the dialer implementation. */
|
|
18
|
+
alpnProtocols?: string[];
|
|
19
|
+
/** Extra Node.js TLS options (minVersion, servername, etc.). */
|
|
20
|
+
extraOptions?: NodeTlsConnectOptions["extraOptions"];
|
|
21
|
+
}
|
|
22
|
+
interface Options {
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Back-compat */
|
|
27
|
+
export type ConnectionLike = Dialer.ConnectionLike;
|
|
28
|
+
/** Back-compat */
|
|
29
|
+
export interface DialTarget extends Dialer.Target {
|
|
30
|
+
}
|
package/types/index.d.ts
ADDED