@browsercore/http1 0.2.0 → 0.2.1
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/README.md +38 -2
- package/dist/connection.d.ts +9 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +39 -6
- package/dist/connection.js.map +1 -1
- package/dist/decompress.d.ts +27 -9
- package/dist/decompress.d.ts.map +1 -1
- package/dist/decompress.js +17 -20
- package/dist/decompress.js.map +1 -1
- package/dist/errors.d.ts +25 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +29 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/message.js +2 -2
- package/dist/message.js.map +1 -1
- package/dist/types.d.ts +57 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +10 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +19 -4
- package/dist/utils.js.map +1 -1
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @browsercore/http1
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@browsercore/http1)
|
|
4
|
-
[](https://github.com/jverneuer/browsercore-http1/blob/main/COVERAGE.md)
|
|
5
5
|
[](https://github.com/jverneuer/browsercore-http1/actions/workflows/ci.yml)
|
|
6
6
|
|
|
7
7
|
An HTTP/1.1 client over any duplex byte stream. Serializes requests, parses
|
|
@@ -72,7 +72,43 @@ try {
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
`@browsercore/compression` wraps `node:zlib`; `@browsercore/http1` calls it
|
|
75
|
-
never `node:zlib` directly.
|
|
75
|
+
never `node:zlib` directly. `@browsercore/http1` does NOT import `node:events`
|
|
76
|
+
— event emission is composed exclusively through the injected `EventProvider`
|
|
77
|
+
on the `Transport` it consumes (browsersmith is the composition root that
|
|
78
|
+
provides the runtime backend).
|
|
79
|
+
|
|
80
|
+
## Platform threading
|
|
81
|
+
|
|
82
|
+
`Http1Options` accepts an optional `platform?: Platform` field. When supplied,
|
|
83
|
+
any service not passed as an individual field is resolved from the Platform
|
|
84
|
+
composition root:
|
|
85
|
+
|
|
86
|
+
| Option field | Resolved from |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `decompressionProvider` | `platform.compression` |
|
|
89
|
+
| `clock` | `platform.time.clock` |
|
|
90
|
+
|
|
91
|
+
Individual fields always take precedence, so existing callers that pass
|
|
92
|
+
`decompressionProvider`/`clock` directly keep working unchanged. This is the
|
|
93
|
+
migration path toward DI through Platform: callers move from passing individual
|
|
94
|
+
service fields to threading a single Platform (assembled by `browsersmith`) through
|
|
95
|
+
every protocol package. See `@browsercore/contracts` for the `Platform` interface.
|
|
96
|
+
|
|
97
|
+
## Position in BrowserCore
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
Application
|
|
101
|
+
│
|
|
102
|
+
@browsercore/http1
|
|
103
|
+
│
|
|
104
|
+
@browsercore/tls
|
|
105
|
+
│
|
|
106
|
+
@browsercore/transport
|
|
107
|
+
│
|
|
108
|
+
TCP
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Every higher networking layer communicates with the network exclusively through the layers below it.
|
|
76
112
|
|
|
77
113
|
## License
|
|
78
114
|
|
package/dist/connection.d.ts
CHANGED
|
@@ -4,12 +4,20 @@
|
|
|
4
4
|
* Wires the message parser/serializer over a `@browsercore/transport` duplex byte
|
|
5
5
|
* stream. Handles keep-alive via serial request/response on a single connection.
|
|
6
6
|
*/
|
|
7
|
-
import type
|
|
7
|
+
import { type Http1CloseReason, type Http1Connection, type Http1ConnectionId, type Http1ConnectionState, type Http1Options, type HttpRequest, type HttpResponse } from "./types.js";
|
|
8
8
|
/** Concrete HTTP/1.1 connection. */
|
|
9
9
|
export declare class Http1ConnectionImpl implements Http1Connection {
|
|
10
10
|
private readonly options;
|
|
11
11
|
readonly id: Http1ConnectionId;
|
|
12
12
|
state: Http1ConnectionState;
|
|
13
|
+
/**
|
|
14
|
+
* Resolved decompression backend. Prefers the explicit
|
|
15
|
+
* {@link Http1Options.decompressionProvider}, then
|
|
16
|
+
* {@link Http1Options.platform}.compression. When both are absent and a
|
|
17
|
+
* response carries a `content-encoding`, the connection raises
|
|
18
|
+
* {@link ContentEncodingError}.
|
|
19
|
+
*/
|
|
20
|
+
private readonly decompressionProvider;
|
|
13
21
|
/**
|
|
14
22
|
* Incoming bytes not yet consumed by a parsed response. Drained by
|
|
15
23
|
* `bytesConsumed` after every parse — this is what makes keep-alive work.
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEH,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EAEpB,MAAM,YAAY,CAAC;AAqBpB,oCAAoC;AACpC,qBAAa,mBAAoB,YAAW,eAAe;IAuCnD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAtC5B,SAAgB,EAAE,EAAE,iBAAiB,CAAC;IAC/B,KAAK,EAAE,oBAAoB,CAAqB;IAEvD;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAoC;IAE1E;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAiC;IAE/C,mEAAmE;IACnE,OAAO,CAAC,WAAW,CAAyC;IAE5D,kFAAkF;IAClF,OAAO,CAAC,YAAY,CAAyB;IAE7C,6EAA6E;IAC7E,OAAO,CAAC,eAAe,CAAS;IAEhC;;;;;;OAMG;IACH,OAAO,CAAC,OAAO,CAAK;IAEpB,YACI,EAAE,EAAE,iBAAiB,EACJ,OAAO,EAAE,YAAY,EA2BzC;IAEY,OAAO,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAmC5D;IAEY,KAAK,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmB3D;IAED,OAAO,CAAC,iBAAiB;IAKzB,4EAA4E;YAC9D,YAAY;IA0B1B;;;OAGG;YACW,QAAQ;IAqCtB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAMrB;;;;OAIG;YACW,UAAU;IAuBxB,4EAA4E;IAC5E,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,UAAU;IAIlB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;IASjB;;;OAGG;IACH,OAAO,CAAC,aAAa;CAoBxB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAQ5E"}
|
package/dist/connection.js
CHANGED
|
@@ -4,15 +4,26 @@
|
|
|
4
4
|
* Wires the message parser/serializer over a `@browsercore/transport` duplex byte
|
|
5
5
|
* stream. Handles keep-alive via serial request/response on a single connection.
|
|
6
6
|
*/
|
|
7
|
+
import { systemClock, } from "./types.js";
|
|
7
8
|
import { parseResponse, serializeRequest, parseChunkedEncoding } from "./message.js";
|
|
8
9
|
import { decompressBody } from "./decompress.js";
|
|
9
10
|
import { assertNever, createId, createDeferred, decodeAscii } from "./utils.js";
|
|
11
|
+
import { createRandomSource } from "@browsercore/transport";
|
|
12
|
+
import { ConnectionClosedError, ConnectionClosingError, ContentEncodingError, } from "./errors.js";
|
|
10
13
|
import { collectSetCookie, describeCloseReason, extractContentLength, findChunkedBodyEnd, findHeaderEnd, isChunkedEncoding, materialize, chunkIterable, } from "./connection-helpers.js";
|
|
11
14
|
/** Concrete HTTP/1.1 connection. */
|
|
12
15
|
export class Http1ConnectionImpl {
|
|
13
16
|
options;
|
|
14
17
|
id;
|
|
15
18
|
state = { state: "idle" };
|
|
19
|
+
/**
|
|
20
|
+
* Resolved decompression backend. Prefers the explicit
|
|
21
|
+
* {@link Http1Options.decompressionProvider}, then
|
|
22
|
+
* {@link Http1Options.platform}.compression. When both are absent and a
|
|
23
|
+
* response carries a `content-encoding`, the connection raises
|
|
24
|
+
* {@link ContentEncodingError}.
|
|
25
|
+
*/
|
|
26
|
+
decompressionProvider;
|
|
16
27
|
/**
|
|
17
28
|
* Incoming bytes not yet consumed by a parsed response. Drained by
|
|
18
29
|
* `bytesConsumed` after every parse — this is what makes keep-alive work.
|
|
@@ -35,7 +46,14 @@ export class Http1ConnectionImpl {
|
|
|
35
46
|
constructor(id, options) {
|
|
36
47
|
this.options = options;
|
|
37
48
|
this.id = id;
|
|
38
|
-
|
|
49
|
+
// Resolve the decompression backend: explicit option → platform.compression.
|
|
50
|
+
this.decompressionProvider = options.decompressionProvider
|
|
51
|
+
?? options.platform?.compression;
|
|
52
|
+
// Transport's EventProvider.on emits with a generic
|
|
53
|
+
// `(...args: unknown[])` signature — narrow the first arg to the byte
|
|
54
|
+
// chunk this stream surface always delivers.
|
|
55
|
+
this.options.transport.on("data", (...args) => {
|
|
56
|
+
const chunk = args[0];
|
|
39
57
|
this.appendBuffer(chunk);
|
|
40
58
|
const waiter = this.dataWaiters.shift();
|
|
41
59
|
if (waiter !== undefined) {
|
|
@@ -130,7 +148,7 @@ export class Http1ConnectionImpl {
|
|
|
130
148
|
this.buffer = this.buffer.slice(0, 0);
|
|
131
149
|
return this.decodeBody(response);
|
|
132
150
|
}
|
|
133
|
-
throw new
|
|
151
|
+
throw new ConnectionClosedError();
|
|
134
152
|
}
|
|
135
153
|
// The chunk was already appended to the buffer by the "data" event
|
|
136
154
|
// handler, which also woke this waiter. Nothing more to do here.
|
|
@@ -196,7 +214,14 @@ export class Http1ConnectionImpl {
|
|
|
196
214
|
}
|
|
197
215
|
const contentEncoding = response.headers.get("content-encoding");
|
|
198
216
|
if (contentEncoding !== undefined) {
|
|
199
|
-
|
|
217
|
+
const provider = this.decompressionProvider;
|
|
218
|
+
if (provider === undefined) {
|
|
219
|
+
// No backend was injected — we cannot safely decode. Raising
|
|
220
|
+
// here keeps the "no corrupt bytes" invariant instead of
|
|
221
|
+
// returning the compressed body as-is.
|
|
222
|
+
throw new ContentEncodingError(contentEncoding);
|
|
223
|
+
}
|
|
224
|
+
body = decompressBody(body, contentEncoding, provider);
|
|
200
225
|
}
|
|
201
226
|
return { ...response, body };
|
|
202
227
|
}
|
|
@@ -205,7 +230,10 @@ export class Http1ConnectionImpl {
|
|
|
205
230
|
return new Promise((resolve) => {
|
|
206
231
|
this.dataWaiters.push((chunk) => {
|
|
207
232
|
if (this.transportClosed && chunk.length === 0) {
|
|
208
|
-
|
|
233
|
+
// Resolver param is `(value: Uint8Array | undefined) => void`
|
|
234
|
+
// (non-optional), so `undefined` must be passed explicitly.
|
|
235
|
+
// oxlint-disable-next-line unicorn/no-useless-undefined
|
|
236
|
+
resolve(undefined);
|
|
209
237
|
}
|
|
210
238
|
else {
|
|
211
239
|
resolve(chunk);
|
|
@@ -229,7 +257,7 @@ export class Http1ConnectionImpl {
|
|
|
229
257
|
case "in_flight":
|
|
230
258
|
return;
|
|
231
259
|
case "closing":
|
|
232
|
-
throw new
|
|
260
|
+
throw new ConnectionClosingError();
|
|
233
261
|
case "closed":
|
|
234
262
|
throw new Error(`connection is closed: ${describeCloseReason(s.reason)}`);
|
|
235
263
|
default:
|
|
@@ -285,7 +313,12 @@ export class Http1ConnectionImpl {
|
|
|
285
313
|
* it with the HTTP/1.1 protocol state machine.
|
|
286
314
|
*/
|
|
287
315
|
export function connectHttp1(options) {
|
|
288
|
-
const
|
|
316
|
+
const random = options.random ?? createRandomSource();
|
|
317
|
+
// Resolve the clock: explicit option → platform.time.clock → systemClock.
|
|
318
|
+
const clock = options.clock
|
|
319
|
+
?? options.platform?.time?.clock
|
|
320
|
+
?? systemClock;
|
|
321
|
+
const id = createId("http1", random, clock);
|
|
289
322
|
return Promise.resolve(new Http1ConnectionImpl(id, options));
|
|
290
323
|
}
|
|
291
324
|
//# sourceMappingURL=connection.js.map
|
package/dist/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EASH,WAAW,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,cAAc,EAA8B,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACH,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,aAAa,GAChB,MAAM,yBAAyB,CAAC;AAEjC,oCAAoC;AACpC,MAAM,OAAO,mBAAmB;IAuCP,OAAO;IAtCZ,EAAE,CAAoB;IAC/B,KAAK,GAAyB,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAEvD;;;;;;OAMG;IACc,qBAAqB,CAAoC;IAE1E;;;OAGG;IACK,MAAM,GAAe,IAAI,UAAU,CAAC,CAAC,CA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Content-encoding decompression for HTTP/1.1 responses.
|
|
3
3
|
*
|
|
4
4
|
* Pure function — operates on the full buffered body bytes (after any
|
|
5
|
-
* transfer-encoding has been removed).
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* transfer-encoding has been removed). http1 does NOT own a zlib backend — a
|
|
6
|
+
* {@link DecompressionProvider} is injected by the caller (typically
|
|
7
|
+
* @browsercore/fetch) so this package never imports @browsercore/compression
|
|
8
|
+
* directly (that was a layering violation: http1 composes over @browsercore/*
|
|
9
|
+
* packages *below* it; compression is a sibling, reached only via fetch).
|
|
10
|
+
* Any failure to decompress is mapped onto HTTP/1.1's
|
|
11
|
+
* {@link ContentEncodingError} — the original provider error is preserved as
|
|
12
|
+
* `cause` so nothing is hidden.
|
|
8
13
|
*
|
|
9
14
|
* Kept out of `message.ts` so the message parser stays a pure wire-format
|
|
10
15
|
* function with no dependency on zlib.
|
|
11
16
|
*/
|
|
12
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The decompression backend seam.
|
|
19
|
+
*
|
|
20
|
+
* http1 depends only on this interface, never on a concrete zlib provider.
|
|
21
|
+
* The caller (typically @browsercore/fetch) injects an implementation —
|
|
22
|
+
* the platform's compression adapter (composed in browsersmith). `decompress`
|
|
23
|
+
* full body bytes and the `content-encoding` header value and must return the
|
|
24
|
+
* decoded bytes; it may throw on an unsupported or corrupt stream (http1 wraps
|
|
25
|
+
* any thrown error as a {@link ContentEncodingError}).
|
|
26
|
+
*/
|
|
27
|
+
export interface DecompressionProvider {
|
|
28
|
+
/** Decompress a body according to a `content-encoding` header value. */
|
|
29
|
+
decompress(data: Uint8Array, encoding: string): Uint8Array;
|
|
30
|
+
}
|
|
13
31
|
/** Content-encoding values we can decode — literal union, never bare `string`. */
|
|
14
32
|
export type ContentEncoding = "gzip" | "deflate" | "br";
|
|
15
33
|
/** Whether `value` is a content-encoding we know how to decode. */
|
|
@@ -18,11 +36,11 @@ export declare function isSupportedContentEncoding(value: string): value is Cont
|
|
|
18
36
|
* Decompress a body according to a `content-encoding` header value.
|
|
19
37
|
*
|
|
20
38
|
* For `deflate`, servers disagree on framing: some send a zlib-wrapped stream
|
|
21
|
-
* (what the RFC calls for), some send raw deflate. The
|
|
22
|
-
*
|
|
23
|
-
* browser tolerance.
|
|
39
|
+
* (what the RFC calls for), some send raw deflate. The injected provider is
|
|
40
|
+
* expected to mirror browser tolerance (try zlib first, fall back to raw).
|
|
24
41
|
*
|
|
25
|
-
* @throws {ContentEncodingError} on
|
|
42
|
+
* @throws {ContentEncodingError} on any decompression failure — the original
|
|
43
|
+
* provider error is attached as `cause`.
|
|
26
44
|
*/
|
|
27
|
-
export declare function decompressBody(body: Uint8Array, encoding: string, provider
|
|
45
|
+
export declare function decompressBody(body: Uint8Array, encoding: string, provider: DecompressionProvider): Uint8Array;
|
|
28
46
|
//# sourceMappingURL=decompress.d.ts.map
|
package/dist/decompress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAqB;IAClC,wEAAwE;IACxE,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;CAC9D;AAED,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAIxD,mEAAmE;AACnE,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,eAAe,CAElF;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC1B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,qBAAqB,GAChC,UAAU,CASZ"}
|
package/dist/decompress.js
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
* Content-encoding decompression for HTTP/1.1 responses.
|
|
3
3
|
*
|
|
4
4
|
* Pure function — operates on the full buffered body bytes (after any
|
|
5
|
-
* transfer-encoding has been removed).
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* transfer-encoding has been removed). http1 does NOT own a zlib backend — a
|
|
6
|
+
* {@link DecompressionProvider} is injected by the caller (typically
|
|
7
|
+
* @browsercore/fetch) so this package never imports @browsercore/compression
|
|
8
|
+
* directly (that was a layering violation: http1 composes over @browsercore/*
|
|
9
|
+
* packages *below* it; compression is a sibling, reached only via fetch).
|
|
10
|
+
* Any failure to decompress is mapped onto HTTP/1.1's
|
|
11
|
+
* {@link ContentEncodingError} — the original provider error is preserved as
|
|
12
|
+
* `cause` so nothing is hidden.
|
|
8
13
|
*
|
|
9
14
|
* Kept out of `message.ts` so the message parser stays a pure wire-format
|
|
10
15
|
* function with no dependency on zlib.
|
|
11
16
|
*/
|
|
12
|
-
import { compression, DecompressionError, UnsupportedEncodingError, } from "@browsercore/compression";
|
|
13
17
|
import { ContentEncodingError } from "./errors.js";
|
|
14
18
|
const SUPPORTED_ENCODINGS = ["gzip", "deflate", "br"];
|
|
15
19
|
/** Whether `value` is a content-encoding we know how to decode. */
|
|
@@ -20,28 +24,21 @@ export function isSupportedContentEncoding(value) {
|
|
|
20
24
|
* Decompress a body according to a `content-encoding` header value.
|
|
21
25
|
*
|
|
22
26
|
* For `deflate`, servers disagree on framing: some send a zlib-wrapped stream
|
|
23
|
-
* (what the RFC calls for), some send raw deflate. The
|
|
24
|
-
*
|
|
25
|
-
* browser tolerance.
|
|
27
|
+
* (what the RFC calls for), some send raw deflate. The injected provider is
|
|
28
|
+
* expected to mirror browser tolerance (try zlib first, fall back to raw).
|
|
26
29
|
*
|
|
27
|
-
* @throws {ContentEncodingError} on
|
|
30
|
+
* @throws {ContentEncodingError} on any decompression failure — the original
|
|
31
|
+
* provider error is attached as `cause`.
|
|
28
32
|
*/
|
|
29
|
-
export function decompressBody(body, encoding, provider
|
|
33
|
+
export function decompressBody(body, encoding, provider) {
|
|
30
34
|
try {
|
|
31
35
|
return provider.decompress(body, encoding);
|
|
32
36
|
}
|
|
33
37
|
catch (err) {
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
if (err instanceof DecompressionError) {
|
|
40
|
-
throw new ContentEncodingError(err.encoding, { cause: err });
|
|
41
|
-
}
|
|
42
|
-
// Anything else is unexpected from a well-behaved provider — let it
|
|
43
|
-
// propagate rather than swallowing it behind a ContentEncodingError.
|
|
44
|
-
throw err;
|
|
38
|
+
// Normalize non-Error throws (a provider may throw anything) into an
|
|
39
|
+
// Error before attaching as cause, so the contract holds either way.
|
|
40
|
+
const cause = err instanceof Error ? err : new Error(String(err));
|
|
41
|
+
throw new ContentEncodingError(encoding, { cause });
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
//# sourceMappingURL=decompress.js.map
|
package/dist/decompress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAoBnD,MAAM,mBAAmB,GAA+B,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AAElF,mEAAmE;AACnE,MAAM,UAAU,0BAA0B,CAAC,KAAa;IACpD,OAAQ,mBAAyC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC1B,IAAgB,EAChB,QAAgB,EAChB,QAA+B;IAE/B,IAAI,CAAC;QACD,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,qEAAqE;QACrE,qEAAqE;QACrE,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,MAAM,IAAI,oBAAoB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACxD,CAAC;AACL,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* can match on `kind` instead of parsing messages.
|
|
6
6
|
*/
|
|
7
7
|
/** Discriminated union of all HTTP/1.1 error kinds. */
|
|
8
|
-
export type Http1ErrorKind = "Http1Error" | "RedirectLimitError" | "InvalidResponseError" | "ContentEncodingError" | "ChunkEncodingError";
|
|
8
|
+
export type Http1ErrorKind = "Http1Error" | "RedirectLimitError" | "InvalidResponseError" | "ContentEncodingError" | "ChunkEncodingError" | "ConnectionClosedError" | "ConnectionClosingError" | "DecodeError";
|
|
9
9
|
/** Base class for all HTTP/1.1 errors. */
|
|
10
10
|
export declare class Http1Error extends Error {
|
|
11
11
|
readonly kind: Http1ErrorKind;
|
|
@@ -55,4 +55,28 @@ export declare class ChunkEncodingError extends Http1Error {
|
|
|
55
55
|
cause?: Error;
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
/** The transport closed before a complete response was received. */
|
|
59
|
+
export declare class ConnectionClosedError extends Http1Error {
|
|
60
|
+
readonly kind: "ConnectionClosedError";
|
|
61
|
+
constructor(options?: {
|
|
62
|
+
cause?: Error;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** A new request was attempted on a connection that is closing. */
|
|
66
|
+
export declare class ConnectionClosingError extends Http1Error {
|
|
67
|
+
readonly kind: "ConnectionClosingError";
|
|
68
|
+
constructor(options?: {
|
|
69
|
+
cause?: Error;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** A slice of bytes could not be decoded as ASCII. */
|
|
73
|
+
export declare class DecodeError extends Http1Error {
|
|
74
|
+
readonly kind: "DecodeError";
|
|
75
|
+
/** The index in the buffer that was out of bounds. */
|
|
76
|
+
readonly index: number;
|
|
77
|
+
readonly cause: Error | undefined;
|
|
78
|
+
constructor(index: number, options?: {
|
|
79
|
+
cause?: Error;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
58
82
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uDAAuD;AACvD,MAAM,MAAM,cAAc,GACpB,YAAY,GACZ,oBAAoB,GACpB,sBAAsB,GACtB,sBAAsB,GACtB,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uDAAuD;AACvD,MAAM,MAAM,cAAc,GACpB,YAAY,GACZ,oBAAoB,GACpB,sBAAsB,GACtB,sBAAsB,GACtB,oBAAoB,GACpB,uBAAuB,GACvB,wBAAwB,GACxB,aAAa,CAAC;AAEpB,0CAA0C;AAC1C,qBAAa,UAAW,SAAQ,KAAK;IACjC,SAAgB,IAAI,EAAE,cAAc,CAAgB;IACpD,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IAElD,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,EAIvD;CACJ;AAED,iEAAiE;AACjE,qBAAa,kBAAmB,SAAQ,UAAU;IAC9C,SAAyB,IAAI,EAAG,oBAAoB,CAAU;IAC9D,SAAgB,KAA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;IACjD,SAAyB,IAAI,EAAG,uBAAuB,CAAU;IAEjE,YAAY,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,EAGtC;CACJ;AAED,mEAAmE;AACnE,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,SAAyB,IAAI,EAAG,wBAAwB,CAAU;IAElE,YAAY,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,EAGtC;CACJ;AAED,sDAAsD;AACtD,qBAAa,WAAY,SAAQ,UAAU;IACvC,SAAyB,IAAI,EAAG,aAAa,CAAU;IACvD,sDAAsD;IACtD,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IAElD,YAAY,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,EAKrD;CACJ"}
|
package/dist/errors.js
CHANGED
|
@@ -68,4 +68,33 @@ export class ChunkEncodingError extends Http1Error {
|
|
|
68
68
|
this.cause = options?.cause;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
/** The transport closed before a complete response was received. */
|
|
72
|
+
export class ConnectionClosedError extends Http1Error {
|
|
73
|
+
kind = "ConnectionClosedError";
|
|
74
|
+
constructor(options) {
|
|
75
|
+
super("transport closed before response received", options);
|
|
76
|
+
this.name = "ConnectionClosedError";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** A new request was attempted on a connection that is closing. */
|
|
80
|
+
export class ConnectionClosingError extends Http1Error {
|
|
81
|
+
kind = "ConnectionClosingError";
|
|
82
|
+
constructor(options) {
|
|
83
|
+
super("connection is closing — no new requests allowed", options);
|
|
84
|
+
this.name = "ConnectionClosingError";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** A slice of bytes could not be decoded as ASCII. */
|
|
88
|
+
export class DecodeError extends Http1Error {
|
|
89
|
+
kind = "DecodeError";
|
|
90
|
+
/** The index in the buffer that was out of bounds. */
|
|
91
|
+
index;
|
|
92
|
+
cause;
|
|
93
|
+
constructor(index, options) {
|
|
94
|
+
super(`decodeAscii: index out of bounds at position ${index}`);
|
|
95
|
+
this.name = "DecodeError";
|
|
96
|
+
this.index = index;
|
|
97
|
+
this.cause = options?.cause;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
71
100
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,0CAA0C;AAC1C,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjB,IAAI,GAAmB,YAAY,CAAC;IAC3B,KAAK,CAAoB;IAElD,YAAY,OAAe,EAAE,OAA2B;QACpD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;IAChC,CAAC;CACJ;AAED,iEAAiE;AACjE,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IACrB,IAAI,GAAG,oBAA6B,CAAC;IAC9C,KAAK,CAAS;IAC9B,+EAA+E;IAC/D,KAAK,CAAoB;IAChB,KAAK,CAAoB;IAElD,YAAY,KAAa,EAAE,KAAwB,EAAE,OAA2B;QAC5E,KAAK,CAAC,qBAAqB,KAAK,oBAAoB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzE,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK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;AAED,oEAAoE;AACpE,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IACxB,IAAI,GAAG,uBAAgC,CAAC;IAEjE,YAAY,OAA2B;QACnC,KAAK,CAAC,2CAA2C,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACxC,CAAC;CACJ;AAED,mEAAmE;AACnE,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IACzB,IAAI,GAAG,wBAAiC,CAAC;IAElE,YAAY,OAA2B;QACnC,KAAK,CAAC,iDAAiD,EAAE,OAAO,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACzC,CAAC;CACJ;AAED,sDAAsD;AACtD,MAAM,OAAO,WAAY,SAAQ,UAAU;IACd,IAAI,GAAG,aAAsB,CAAC;IACvD,sDAAsD;IACtC,KAAK,CAAS;IACL,KAAK,CAAoB;IAElD,YAAY,KAAa,EAAE,OAA2B;QAClD,KAAK,CAAC,gDAAgD,KAAK,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;IAChC,CAAC;CACJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* Higher layers (cookies, fetch, profiles) compose exclusively through these exports.
|
|
6
6
|
*/
|
|
7
7
|
export { connectHttp1, Http1ConnectionImpl } from "./connection.js";
|
|
8
|
-
export { ChunkEncodingError, ContentEncodingError, Http1Error, InvalidResponseError, RedirectLimitError, } from "./errors.js";
|
|
8
|
+
export { ChunkEncodingError, ConnectionClosedError, ConnectionClosingError, ContentEncodingError, DecodeError, Http1Error, InvalidResponseError, RedirectLimitError, } from "./errors.js";
|
|
9
9
|
export { type Headers, type ParseResponseResult, type StartLine, parseChunkedEncoding, parseResponse, serializeRequest, } from "./message.js";
|
|
10
|
-
export { decompressBody, isSupportedContentEncoding, type ContentEncoding } from "./decompress.js";
|
|
10
|
+
export { decompressBody, isSupportedContentEncoding, type ContentEncoding, type DecompressionProvider, } from "./decompress.js";
|
|
11
11
|
export { followRedirects, isRedirectStatus, resolveRedirectUrl, type FollowRedirectsOptions, type RedirectStatusCode, } from "./redirect.js";
|
|
12
12
|
export { type Http1CloseReason, type Http1Connection, type Http1ConnectionId, type Http1ConnectionState, type Http1Options, type HttpBodyKind, type HttpMethod, type HttpRequest, type HttpResponse, type CookieInterceptor, type CookieUrl, } from "./types.js";
|
|
13
13
|
export { assertNever } from "./utils.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,oBAAoB,EACpB,kBAAkB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,oBAAoB,EACpB,aAAa,EACb,gBAAgB,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EACH,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,oBAAoB,EACpB,kBAAkB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,oBAAoB,EACpB,aAAa,EACb,gBAAgB,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACH,cAAc,EACd,0BAA0B,EAC1B,KAAK,eAAe,EACpB,KAAK,qBAAqB,GAC7B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,GAC1B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACH,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,SAAS,GACjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* Higher layers (cookies, fetch, profiles) compose exclusively through these exports.
|
|
6
6
|
*/
|
|
7
7
|
export { connectHttp1, Http1ConnectionImpl } from "./connection.js";
|
|
8
|
-
export { ChunkEncodingError, ContentEncodingError, Http1Error, InvalidResponseError, RedirectLimitError, } from "./errors.js";
|
|
8
|
+
export { ChunkEncodingError, ConnectionClosedError, ConnectionClosingError, ContentEncodingError, DecodeError, Http1Error, InvalidResponseError, RedirectLimitError, } from "./errors.js";
|
|
9
9
|
export { parseChunkedEncoding, parseResponse, serializeRequest, } from "./message.js";
|
|
10
|
-
export { decompressBody, isSupportedContentEncoding } from "./decompress.js";
|
|
10
|
+
export { decompressBody, isSupportedContentEncoding, } from "./decompress.js";
|
|
11
11
|
export { followRedirects, isRedirectStatus, resolveRedirectUrl, } from "./redirect.js";
|
|
12
12
|
export {} from "./types.js";
|
|
13
13
|
export { assertNever } from "./utils.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,oBAAoB,EACpB,kBAAkB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EAIH,oBAAoB,EACpB,aAAa,EACb,gBAAgB,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EACH,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,oBAAoB,EACpB,kBAAkB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EAIH,oBAAoB,EACpB,aAAa,EACb,gBAAgB,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACH,cAAc,EACd,0BAA0B,GAG7B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GAGrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAYN,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/message.js
CHANGED
|
@@ -19,7 +19,7 @@ export function serializeRequest(req) {
|
|
|
19
19
|
lines.push(`${name.toLowerCase()}: ${value}`);
|
|
20
20
|
}
|
|
21
21
|
lines.push("", "");
|
|
22
|
-
const headerBytes =
|
|
22
|
+
const headerBytes = new TextEncoder().encode(lines.join("\r\n"));
|
|
23
23
|
switch (req.body.kind) {
|
|
24
24
|
case "empty":
|
|
25
25
|
return new Uint8Array(headerBytes);
|
|
@@ -42,7 +42,7 @@ export function serializeRequest(req) {
|
|
|
42
42
|
* @throws {InvalidResponseError} if the bytes cannot be parsed as a response.
|
|
43
43
|
*/
|
|
44
44
|
export function parseResponse(buf) {
|
|
45
|
-
const text =
|
|
45
|
+
const text = decodeAscii(buf, 0, buf.length);
|
|
46
46
|
const headerEnd = text.indexOf("\r\n\r\n");
|
|
47
47
|
if (headerEnd === -1) {
|
|
48
48
|
throw new InvalidResponseError(text.slice(0, 120));
|
package/dist/message.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAgBvE;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAgB;IAC7C,MAAM,KAAK,GAAa,CAAC,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC;IAC9D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;QACtC,2EAA2E;QAC3E,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACnB,MAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAgBvE;;;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AAI,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC3D,MAAM,IAAI,kBAAkB,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC;YACrD,CAAC;YAED,MAAM,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACvC,QAAQ,IAAI,QAAQ,CAAC;YACrB,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC;IACL,CAAC;IAED,0DAA0D;IAC1D,MAAM,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* HTTP/1.1 client over any duplex byte stream. This package owns NO knowledge
|
|
5
5
|
* of TLS, TCP, or DNS — it composes exclusively over `@browsercore/transport`.
|
|
6
6
|
*/
|
|
7
|
-
import type { Transport } from "@browsercore/transport";
|
|
7
|
+
import type { RandomSource, Transport } from "@browsercore/transport";
|
|
8
|
+
import type { DecompressionProvider } from "./decompress.js";
|
|
9
|
+
import type { Platform } from "@browsercore/contracts";
|
|
10
|
+
export type { RandomSource };
|
|
8
11
|
/** Branded HTTP/1.1 connection identifier. */
|
|
9
12
|
export type Http1ConnectionId = string & {
|
|
10
13
|
__brand: "Http1ConnectionId";
|
|
@@ -78,6 +81,21 @@ export interface Http1Connection {
|
|
|
78
81
|
/** Gracefully close the connection. Resolves once no requests are in flight. */
|
|
79
82
|
close(reason?: Http1CloseReason): Promise<void>;
|
|
80
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Clock for time-dependent operations. Injected via {@link Http1Options} so
|
|
86
|
+
* callers control the time source — keeps the package testable against a
|
|
87
|
+
* deterministic clock (reproducible id generation) and embeddable in non-Node
|
|
88
|
+
* hosts (browsers, workers) where `Date.now()` may not be the desired source.
|
|
89
|
+
*
|
|
90
|
+
* `now()` MUST return milliseconds since the Unix epoch, matching the contract
|
|
91
|
+
* of `Date.now()`.
|
|
92
|
+
*/
|
|
93
|
+
export interface Clock {
|
|
94
|
+
/** Current time in milliseconds since the Unix epoch. */
|
|
95
|
+
now(): number;
|
|
96
|
+
}
|
|
97
|
+
/** The default clock — delegates to the platform `Date.now()`. */
|
|
98
|
+
export declare const systemClock: Clock;
|
|
81
99
|
/**
|
|
82
100
|
* Cookie-jar integration seam.
|
|
83
101
|
*
|
|
@@ -127,5 +145,43 @@ export interface Http1Options {
|
|
|
127
145
|
* http1 performs no cookie storage of its own.
|
|
128
146
|
*/
|
|
129
147
|
readonly cookieInterceptor?: CookieInterceptor;
|
|
148
|
+
/**
|
|
149
|
+
* Content-encoding decompression backend. http1 does NOT own a zlib
|
|
150
|
+
* provider — it depends only on the {@link DecompressionProvider}
|
|
151
|
+
* interface, never on a concrete implementation. The @browsercore/fetch
|
|
152
|
+
* layer injects its platform compression adapter here.
|
|
153
|
+
*
|
|
154
|
+
* When absent and a response carries a `content-encoding`, the connection
|
|
155
|
+
* raises {@link ContentEncodingError} rather than returning corrupt bytes.
|
|
156
|
+
* Ignored when {@link decompressionProvider} is supplied by
|
|
157
|
+
* {@link platform}.
|
|
158
|
+
*/
|
|
159
|
+
readonly decompressionProvider?: DecompressionProvider;
|
|
160
|
+
/**
|
|
161
|
+
* Clock for time-dependent operations. Defaults to {@link systemClock}
|
|
162
|
+
* (delegates to `Date.now()`). Inject a deterministic clock for
|
|
163
|
+
* reproducible ids in tests. Ignored when {@link clock} is supplied by
|
|
164
|
+
* {@link platform}.
|
|
165
|
+
*/
|
|
166
|
+
readonly clock?: Clock;
|
|
167
|
+
/**
|
|
168
|
+
* Source of cryptographically-strong random bytes. Used for connection IDs
|
|
169
|
+
* and any other randomness needs. Defaults to a `node:crypto.randomBytes`
|
|
170
|
+
* backed source (via `createRandomSource()`) when not provided.
|
|
171
|
+
*/
|
|
172
|
+
readonly random?: RandomSource;
|
|
173
|
+
/**
|
|
174
|
+
* The Platform composition root. When supplied, any service not passed as
|
|
175
|
+
* an individual field is resolved from here: `decompressionProvider` from
|
|
176
|
+
* `platform.compression` and `clock` from `platform.time.clock`.
|
|
177
|
+
* Individual fields always take precedence over the platform-supplied
|
|
178
|
+
* value, so existing callers that pass `decompressionProvider`/`clock`
|
|
179
|
+
* directly keep working unchanged.
|
|
180
|
+
*
|
|
181
|
+
* This is the migration path toward DI through Platform: callers move
|
|
182
|
+
* from passing individual service fields to threading a single Platform
|
|
183
|
+
* through every protocol package.
|
|
184
|
+
*/
|
|
185
|
+
readonly platform?: Platform;
|
|
130
186
|
}
|
|
131
187
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAIvD,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B,8CAA8C;AAC9C,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAE1E,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAChB,KAAK,GACL,MAAM,GACN,KAAK,GACL,QAAQ,GACR,OAAO,GACP,MAAM,GACN,SAAS,GACT,OAAO,GACP,SAAS,CAAC;AAEhB;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAClB;IAAE,QAAQ,CAAC,IAAI,EAA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QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAC/C;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IACvD;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAC/B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAChC"}
|
package/dist/types.js
CHANGED
|
@@ -4,5 +4,8 @@
|
|
|
4
4
|
* HTTP/1.1 client over any duplex byte stream. This package owns NO knowledge
|
|
5
5
|
* of TLS, TCP, or DNS — it composes exclusively over `@browsercore/transport`.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
/** The default clock — delegates to the platform `Date.now()`. */
|
|
8
|
+
export const systemClock = {
|
|
9
|
+
now: () => Date.now(),
|
|
10
|
+
};
|
|
8
11
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAuGH,kEAAkE;AAClE,MAAM,CAAC,MAAM,WAAW,GAAU;IAC9B,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;CACxB,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -4,15 +4,22 @@
|
|
|
4
4
|
* Kept dependency-free so every package can copy the pattern without pulling in
|
|
5
5
|
* cross-package imports.
|
|
6
6
|
*/
|
|
7
|
-
import type
|
|
7
|
+
import { type Http1ConnectionId, type Clock, type RandomSource } from "./types.js";
|
|
8
8
|
/**
|
|
9
9
|
* Exhaustiveness check for `switch`/`if-else` over discriminated unions.
|
|
10
10
|
* Call in the `default` branch: `default: assertNever(x)`.
|
|
11
11
|
* Adding a new union member forces every handler to compile-error until handled.
|
|
12
12
|
*/
|
|
13
13
|
export declare function assertNever(x: never): never;
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Generate a branded HTTP/1.1 connection id.
|
|
16
|
+
*
|
|
17
|
+
* The trailing segment is drawn from `random` so the id is unique without
|
|
18
|
+
* relying on `Math.random()`. This is the single sanctioned home for
|
|
19
|
+
* randomness in http1 — other modules must call this rather than reaching for
|
|
20
|
+
* randomness directly.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createId(prefix: string, random: RandomSource, clock?: Clock): Http1ConnectionId;
|
|
16
23
|
/**
|
|
17
24
|
* Explicit handle for a promise that is resolved/rejected from the outside.
|
|
18
25
|
*
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAe,KAAK,iBAAiB,EAAE,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAGhG;;;;GAIG;AAEH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAE3C;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,KAAK,GAAE,KAAmB,GAC3B,iBAAiB,CAQnB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAC/C;AAED,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAQ/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAYtE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAU/E"}
|
package/dist/utils.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Kept dependency-free so every package can copy the pattern without pulling in
|
|
5
5
|
* cross-package imports.
|
|
6
6
|
*/
|
|
7
|
+
import { systemClock } from "./types.js";
|
|
8
|
+
import { DecodeError } from "./errors.js";
|
|
7
9
|
/**
|
|
8
10
|
* Exhaustiveness check for `switch`/`if-else` over discriminated unions.
|
|
9
11
|
* Call in the `default` branch: `default: assertNever(x)`.
|
|
@@ -13,9 +15,22 @@
|
|
|
13
15
|
export function assertNever(x) {
|
|
14
16
|
throw new Error(`Unexpected value: ${JSON.stringify(x)}`);
|
|
15
17
|
}
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Generate a branded HTTP/1.1 connection id.
|
|
20
|
+
*
|
|
21
|
+
* The trailing segment is drawn from `random` so the id is unique without
|
|
22
|
+
* relying on `Math.random()`. This is the single sanctioned home for
|
|
23
|
+
* randomness in http1 — other modules must call this rather than reaching for
|
|
24
|
+
* randomness directly.
|
|
25
|
+
*/
|
|
26
|
+
export function createId(prefix, random, clock = systemClock) {
|
|
27
|
+
// 3 bytes → 24 bits of entropy, plenty for a ~1e6-space suffix.
|
|
28
|
+
const bytes = random.randomBytes(3);
|
|
29
|
+
const hi = bytes[0] ?? 0;
|
|
30
|
+
const mid = bytes[1] ?? 0;
|
|
31
|
+
const lo = bytes[2] ?? 0;
|
|
32
|
+
const suffix = ((hi << 16) | (mid << 8) | lo) % 1_000_000;
|
|
33
|
+
return `${prefix}_${clock.now().toString(36)}_${suffix.toString(36)}`;
|
|
19
34
|
}
|
|
20
35
|
/** Create a {@link Deferred} whose `resolve`/`reject` can be invoked elsewhere. */
|
|
21
36
|
export function createDeferred() {
|
|
@@ -62,7 +77,7 @@ export function decodeAscii(buf, start, end) {
|
|
|
62
77
|
for (let i = start; i < end; i++) {
|
|
63
78
|
const byte = buf[i];
|
|
64
79
|
if (byte === undefined) {
|
|
65
|
-
throw new
|
|
80
|
+
throw new DecodeError(i);
|
|
66
81
|
}
|
|
67
82
|
out += String.fromCodePoint(byte);
|
|
68
83
|
}
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAyD,MAAM,YAAY,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;GAIG;AACH,6DAA6D;AAC7D,MAAM,UAAU,WAAW,CAAC,CAAQ;IAChC,MAAM,IAAI,KA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GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACzC,SAAS;QACb,CAAC;QACD,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YAClB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,+BAA+B;QACjD,CAAC;QACD,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,CAAC,CAAC,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,GAAe,EAAE,KAAa,EAAE,GAAW;IACnE,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;QACD,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browsercore/http1",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "HTTP/1.1 client over any duplex byte stream. No knowledge of TLS or TCP
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "HTTP/1.1 client over any duplex byte stream. No knowledge of TLS or TCP \u2014 only the protocol.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/jverneuer/browsercore-http1.git"
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
15
16
|
"main": "./dist/index.js",
|
|
16
17
|
"types": "./dist/index.d.ts",
|
|
17
18
|
"exports": {
|
|
@@ -22,6 +23,7 @@
|
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|
|
26
|
+
"bin",
|
|
25
27
|
"LICENSE",
|
|
26
28
|
"README.md"
|
|
27
29
|
],
|
|
@@ -31,14 +33,18 @@
|
|
|
31
33
|
},
|
|
32
34
|
"scripts": {
|
|
33
35
|
"clean": "rm -rf dist",
|
|
34
|
-
"build": "tsc -p tsconfig.
|
|
36
|
+
"build": "tsc -p tsconfig.json",
|
|
35
37
|
"prepublishOnly": "npm run clean && npm run build",
|
|
36
38
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
37
39
|
"test": "vitest run",
|
|
38
40
|
"lint": "oxlint --type-aware src/"
|
|
39
41
|
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@browsercore/contracts": "0.2.2",
|
|
44
|
+
"@browsercore/transport": "0.2.5"
|
|
45
|
+
},
|
|
40
46
|
"devDependencies": {
|
|
41
|
-
"@browsercore/
|
|
47
|
+
"@browsercore/compression": "0.2.1",
|
|
42
48
|
"@types/node": "^26.1.2",
|
|
43
49
|
"@vitest/coverage-v8": "^4.1.10",
|
|
44
50
|
"oxlint": "^1.76.0",
|
|
@@ -46,10 +52,6 @@
|
|
|
46
52
|
"typescript": "^7.0.0",
|
|
47
53
|
"vitest": "^4.1.10"
|
|
48
54
|
},
|
|
49
|
-
"dependencies": {
|
|
50
|
-
"@browsercore/compression": "0.2.0",
|
|
51
|
-
"@browsercore/transport": "0.2.0"
|
|
52
|
-
},
|
|
53
55
|
"engines": {
|
|
54
56
|
"node": ">=26.0.0"
|
|
55
57
|
}
|