@browsercore/http1 0.1.3 → 0.1.9

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 CHANGED
@@ -1,52 +1,65 @@
1
1
  # @browsercore/http1
2
2
 
3
- An HTTP/1.1 client over any duplex byte stream.
3
+ [![npm version](https://img.shields.io/npm/v/@browsercore/http1)](https://www.npmjs.com/package/@browsercore/http1)
4
+ [![coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jverneuer/browsercore-http1/coverage/coverage/badge.json)](https://github.com/jverneuer/browsercore-http1/blob/main/COVERAGE.md)
5
+ [![lint](https://img.shields.io/github/actions/workflow/status/jverneuer/browsercore-http1/ci.yml?label=lint)](https://github.com/jverneuer/browsercore-http1/actions/workflows/ci.yml)
4
6
 
5
- ## Responsibility
7
+ An HTTP/1.1 client over any duplex byte stream. Serializes requests, parses
8
+ responses, and manages the HTTP/1.1 protocol state machine — keep-alive, chunked
9
+ transfer-encoding, content-encoding decompression, redirect following, and a
10
+ cookie-header integration seam. Knows nothing about the underlying transport;
11
+ higher layers (`@browsercore/fetch`, `@browsercore/cookies`) compose
12
+ exclusively through its exports.
6
13
 
7
- Serialize requests, parse responses, and manage the HTTP/1.1 protocol state
8
- machine: keep-alive, chunked transfer-encoding, content-encoding compression,
9
- redirect following, and a cookie-header integration seam. The package knows
10
- nothing about the underlying transport — it could be plain TCP, TLS, a pipe, or
11
- a test double.
14
+ ## Install
12
15
 
13
- ## What it does NOT know about
14
-
15
- - TLS / DTLS
16
- - TCP, DNS, or sockets
17
- - HTTP/2 or HTTP/3
18
- - Browser fingerprints
16
+ ```sh
17
+ npm install @browsercore/http1
18
+ ```
19
19
 
20
- ## Public API
20
+ ## Quick usage
21
21
 
22
22
  ```ts
23
23
  import { connectHttp1, RedirectLimitError } from "@browsercore/http1";
24
24
 
25
25
  const conn = await connectHttp1({ transport });
26
- const res = await conn.request({
27
- method: "GET",
28
- url: "/index.html",
29
- headers: new Map([["host", "example.com"]]),
30
- body: { kind: "empty" },
31
- });
32
-
33
- console.log(res.statusCode, res.body);
34
- await conn.close();
26
+ try {
27
+ const res = await conn.request({
28
+ method: "GET",
29
+ url: "/index.html",
30
+ headers: new Map([["host", "example.com"]]),
31
+ body: { kind: "empty" },
32
+ });
33
+ console.log(res.statusCode, res.body);
34
+ } finally {
35
+ await conn.close();
36
+ }
35
37
  ```
36
38
 
37
- ## Types
39
+ ## Public API
38
40
 
39
41
  | Export | Kind | Purpose |
40
42
  | --- | --- | --- |
43
+ | `connectHttp1()` | function | Wrap a transport with the HTTP/1.1 protocol |
41
44
  | `Http1Connection` | interface | Public contract higher layers depend on |
42
- | `connectHttp1()` | function | Wrap a transport with HTTP/1.1 |
45
+ | `Http1ConnectionImpl` | class | Concrete connection (serial request/response) |
43
46
  | `HttpRequest` | interface | Serializable request |
44
47
  | `HttpResponse` | interface | Parsed response |
45
- | `HttpBodyKind` | discriminated union | Empty / bytes / streaming body |
48
+ | `HttpBodyKind` | discriminated union | `empty` / `bytes` body |
49
+ | `HttpMethod` | literal union | Supported HTTP methods |
46
50
  | `Http1ConnectionState` | discriminated union | `idle \| in_flight \| closing \| closed` |
51
+ | `Http1CloseReason` | discriminated union | Why a connection closed |
52
+ | `Http1Options` | interface | Options for `connectHttp1()` |
53
+ | `CookieInterceptor` | interface | Cookie-jar integration seam |
54
+ | `serializeRequest()` | function | Request → wire bytes |
55
+ | `parseResponse()` | function | Wire bytes → response + bytes consumed |
56
+ | `parseChunkedEncoding()` | function | Decode a chunked body stream |
57
+ | `decompressBody()` | function | Decode a `content-encoding` body |
58
+ | `followRedirects()` | function | Standalone redirect-following helper |
47
59
  | `Http1Error` | class | Base typed error |
48
60
  | `RedirectLimitError` | class | Redirect chain exceeded |
49
61
  | `InvalidResponseError` | class | Unparseable response bytes |
62
+ | `ContentEncodingError` | class | Unsupported/corrupt content-encoding |
50
63
  | `ChunkEncodingError` | class | Malformed chunked encoding |
51
64
 
52
65
  ## Dependency graph
@@ -60,3 +73,7 @@ await conn.close();
60
73
 
61
74
  `@browsercore/compression` wraps `node:zlib`; `@browsercore/http1` calls it
62
75
  never `node:zlib` directly.
76
+
77
+ ## License
78
+
79
+ MIT
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Byte-level helpers for {@link Http1ConnectionImpl}.
3
+ *
4
+ * Pure scanning/decoding functions over raw response bytes — factored out of
5
+ * `connection.ts` so the connection class stays focused on lifecycle and
6
+ * request/response orchestration. None of these are exported; they are
7
+ * consumed solely by the connection implementation.
8
+ */
9
+ import type { Http1CloseReason } from "./types.js";
10
+ /** Find the offset of the `\r\n\r\n` header terminator, or -1 if not present. */
11
+ export declare function findHeaderEnd(buf: Uint8Array): number;
12
+ /** Extract the `content-length` header value, or `undefined` if absent. */
13
+ export declare function extractContentLength(headerText: string): number | undefined;
14
+ /** Whether the response uses chunked transfer-encoding. */
15
+ export declare function isChunkedEncoding(headerText: string): boolean;
16
+ /**
17
+ * Find the offset just past the end of a chunked body in `buf`, starting the
18
+ * scan at `bodyStart`. Returns -1 if the terminating chunk has not arrived.
19
+ */
20
+ export declare function findChunkedBodyEnd(buf: Uint8Array, bodyStart: number): number;
21
+ /** Human-readable description of a close reason — for error messages. */
22
+ export declare function describeCloseReason(reason: Http1CloseReason): string;
23
+ /** Yield the bytes of a single buffer as an `AsyncIterable` (one chunk). */
24
+ export declare function chunkIterable(buf: Uint8Array): AsyncIterable<Uint8Array>;
25
+ /** Collect all chunks of an async byte stream into one contiguous buffer. */
26
+ export declare function materialize(stream: AsyncIterable<Uint8Array>): Promise<Uint8Array>;
27
+ /** Collect all `set-cookie` header values (case-insensitive) in wire order. */
28
+ export declare function collectSetCookie(headers: ReadonlyMap<string, string>): string[];
29
+ //# sourceMappingURL=connection-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-helpers.d.ts","sourceRoot":"","sources":["../src/connection-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAYrD;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAO3E;AAED,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAO7D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA+C7E;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAapE;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,CAexE;AAED,6EAA6E;AAC7E,wBAAsB,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAcxF;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,CAQ/E"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Byte-level helpers for {@link Http1ConnectionImpl}.
3
+ *
4
+ * Pure scanning/decoding functions over raw response bytes — factored out of
5
+ * `connection.ts` so the connection class stays focused on lifecycle and
6
+ * request/response orchestration. None of these are exported; they are
7
+ * consumed solely by the connection implementation.
8
+ */
9
+ import { assertNever, decodeAscii, consumeTrailers } from "./utils.js";
10
+ /** Find the offset of the `\r\n\r\n` header terminator, or -1 if not present. */
11
+ export function findHeaderEnd(buf) {
12
+ for (let i = 0; i + 3 < buf.length; i++) {
13
+ if (buf[i] === 0x0d &&
14
+ buf[i + 1] === 0x0a &&
15
+ buf[i + 2] === 0x0d &&
16
+ buf[i + 3] === 0x0a) {
17
+ return i;
18
+ }
19
+ }
20
+ return -1;
21
+ }
22
+ /** Extract the `content-length` header value, or `undefined` if absent. */
23
+ export function extractContentLength(headerText) {
24
+ const match = /(?:^|\n)content-length:\s*(\d+)\r?/iu.exec(headerText);
25
+ if (match === null) {
26
+ return undefined;
27
+ }
28
+ const value = match[1];
29
+ return value === undefined ? undefined : Number(value);
30
+ }
31
+ /** Whether the response uses chunked transfer-encoding. */
32
+ export function isChunkedEncoding(headerText) {
33
+ const match = /(?:^|\n)transfer-encoding:\s*([^\r\n]+)/iu.exec(headerText);
34
+ if (match === null) {
35
+ return false;
36
+ }
37
+ const value = match[1];
38
+ return value !== undefined && value.toLowerCase().includes("chunked");
39
+ }
40
+ /**
41
+ * Find the offset just past the end of a chunked body in `buf`, starting the
42
+ * scan at `bodyStart`. Returns -1 if the terminating chunk has not arrived.
43
+ */
44
+ export function findChunkedBodyEnd(buf, bodyStart) {
45
+ let offset = bodyStart;
46
+ while (offset < buf.length) {
47
+ // Find the end of the chunk-size line.
48
+ let lineEnd = -1;
49
+ for (let i = offset; i + 1 < buf.length; i++) {
50
+ if (buf[i] === 0x0d && buf[i + 1] === 0x0a) {
51
+ lineEnd = i;
52
+ break;
53
+ }
54
+ }
55
+ if (lineEnd === -1) {
56
+ return -1;
57
+ }
58
+ const sizeLine = decodeAscii(buf, offset, lineEnd);
59
+ // exec returns null (not undefined) when there is no match.
60
+ if (!/^[0-9a-fA-F]+(?:;[^\r\n]*)?$/u.test(sizeLine)) {
61
+ return -1;
62
+ }
63
+ const size = Number.parseInt(sizeLine, 16);
64
+ const dataStart = lineEnd + 2;
65
+ if (size === 0) {
66
+ // last-chunk = "1*("0") [ chunk-ext ] CRLF" — no chunk-data, no
67
+ // trailing data CRLF. dataStart points just past the "0\r\n".
68
+ // trailer-part follows: zero or more header-field lines, then a
69
+ // final blank line. consumeTrailers returns the offset just past
70
+ // that final blank line, or -1 if the buffer doesn't hold it all.
71
+ const trailerEnd = consumeTrailers(buf, dataStart);
72
+ return trailerEnd === -1 ? -1 : trailerEnd;
73
+ }
74
+ const dataEnd = dataStart + size;
75
+ const chunkEnd = dataEnd + 2; // trailing \r\n after chunk data
76
+ if (chunkEnd > buf.length) {
77
+ return -1;
78
+ }
79
+ if (buf[dataEnd] !== 0x0d || buf[dataEnd + 1] !== 0x0a) {
80
+ return -1;
81
+ }
82
+ offset = chunkEnd;
83
+ }
84
+ return -1;
85
+ }
86
+ /** Human-readable description of a close reason — for error messages. */
87
+ export function describeCloseReason(reason) {
88
+ switch (reason.kind) {
89
+ case "client_close":
90
+ return "client closed";
91
+ case "remote_close":
92
+ return "remote closed";
93
+ case "error":
94
+ return `error: ${reason.error.message}`;
95
+ case "redirect_jump":
96
+ return `redirect to ${reason.to}`;
97
+ default:
98
+ return assertNever(reason);
99
+ }
100
+ }
101
+ /** Yield the bytes of a single buffer as an `AsyncIterable` (one chunk). */
102
+ export function chunkIterable(buf) {
103
+ let yielded = false;
104
+ return {
105
+ [Symbol.asyncIterator]() {
106
+ return {
107
+ next() {
108
+ if (buf.length === 0 || yielded) {
109
+ return Promise.resolve({ value: undefined, done: true });
110
+ }
111
+ yielded = true;
112
+ return Promise.resolve({ value: buf, done: false });
113
+ },
114
+ };
115
+ },
116
+ };
117
+ }
118
+ /** Collect all chunks of an async byte stream into one contiguous buffer. */
119
+ export async function materialize(stream) {
120
+ const chunks = [];
121
+ let total = 0;
122
+ for await (const chunk of stream) {
123
+ chunks.push(chunk);
124
+ total += chunk.length;
125
+ }
126
+ const out = new Uint8Array(total);
127
+ let offset = 0;
128
+ for (const chunk of chunks) {
129
+ out.set(chunk, offset);
130
+ offset += chunk.length;
131
+ }
132
+ return out;
133
+ }
134
+ /** Collect all `set-cookie` header values (case-insensitive) in wire order. */
135
+ export function collectSetCookie(headers) {
136
+ const out = [];
137
+ for (const [name, value] of headers) {
138
+ if (name === "set-cookie") {
139
+ out.push(value);
140
+ }
141
+ }
142
+ return out;
143
+ }
144
+ //# sourceMappingURL=connection-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-helpers.js","sourceRoot":"","sources":["../src/connection-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEvE,iFAAiF;AACjF,MAAM,UAAU,aAAa,CAAC,GAAe;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IACI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI;YACf,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI;YACnB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI;YACnB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EACrB,CAAC;YACC,OAAO,CAAC,CAAC;QACb,CAAC;IACL,CAAC;IACD,OAAO,CAAC,CAAC,CAAC;AACd,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,oBAAoB,CAAC,UAAkB;IACnD,MAAM,KAAK,GAAG,sCAAsC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtE,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAChD,MAAM,KAAK,GAAG,2CAA2C,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3E,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,OAAO,KAA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@@
7
7
  import type { Http1CloseReason, Http1Connection, Http1ConnectionId, Http1ConnectionState, Http1Options, HttpRequest, HttpResponse } from "./types.js";
8
8
  /** Concrete HTTP/1.1 connection. */
9
9
  export declare class Http1ConnectionImpl implements Http1Connection {
10
- private readonly _options;
10
+ private readonly options;
11
11
  readonly id: Http1ConnectionId;
12
12
  state: Http1ConnectionState;
13
13
  /**
14
14
  * Incoming bytes not yet consumed by a parsed response. Drained by
15
15
  * `bytesConsumed` after every parse — this is what makes keep-alive work.
16
16
  */
17
- private _buffer;
17
+ private buffer;
18
18
  /** Resolvers awaiting the next `data` event from the transport. */
19
- private _dataWaiters;
19
+ private dataWaiters;
20
20
  /** Resolvers awaiting connection close (used by `close()` to drain in-flight). */
21
- private _closeWaiters;
21
+ private closeWaiters;
22
22
  /** Set once the transport has closed unexpectedly (remote close / error). */
23
- private _transportClosed;
24
- constructor(id: Http1ConnectionId, _options: Http1Options);
23
+ private transportClosed;
24
+ /**
25
+ * Number of requests currently in flight. Held as a field rather than
26
+ * derived from `state` because `close()` transitions the discriminant to
27
+ * `"closing"` while requests are still pending — deriving the count from
28
+ * the discriminant would read 0 in that state and the final request's
29
+ * finally block would never wake the draining close waiter.
30
+ */
31
+ private pending;
32
+ constructor(id: Http1ConnectionId, options: Http1Options);
25
33
  request(req: HttpRequest): Promise<HttpResponse>;
26
34
  close(reason?: Http1CloseReason): Promise<void>;
27
- private _isClosedOrClosing;
35
+ private isClosedOrClosing;
28
36
  /** Read bytes from the transport until a complete response is available. */
29
- private _readResponse;
37
+ private readResponse;
30
38
  /**
31
39
  * Attempt to parse a complete response from the current buffer.
32
40
  * Returns `undefined` if more bytes are needed.
33
41
  */
34
- private _tryParse;
42
+ private tryParse;
35
43
  /**
36
44
  * Parse the first `totalLength` bytes, drain them from the buffer, then
37
45
  * decode transfer-encoding (chunked) and content-encoding in the correct
38
46
  * order: transfer-encoding first (it's the outer framing), then
39
47
  * content-encoding on the reassembled bytes.
40
48
  */
41
- private _parseAndDrain;
49
+ private parseAndDrain;
42
50
  /**
43
51
  * Apply transfer-encoding (chunked) decoding then content-encoding
44
52
  * decompression to a parsed response's body. `parseResponse` is kept pure
45
53
  * (wire-format only); this is where protocol semantics get applied.
46
54
  */
47
- private _decodeBody;
55
+ private decodeBody;
48
56
  /** Read one chunk from the transport, or `undefined` once it has closed. */
49
- private _readChunk;
50
- private _appendBuffer;
51
- private _ensureOpen;
52
- private _transition;
53
- /** Derive the current pending count from the state. */
54
- private _pendingCount;
57
+ private readChunk;
58
+ private appendBuffer;
59
+ private ensureOpen;
60
+ private transition;
55
61
  /**
56
62
  * Build the cookie-matching URL for a request.
57
63
  *
@@ -61,12 +67,12 @@ export declare class Http1ConnectionImpl implements Http1Connection {
61
67
  * (this stack is built for TLS). The seam is optional and only invoked when
62
68
  * a caller supplies an interceptor.
63
69
  */
64
- private _cookieUrl;
70
+ private cookieUrl;
65
71
  /**
66
72
  * Merge cookies returned by the interceptor into a request. A bare string
67
73
  * is treated as the `Cookie` header value; a map is merged name->value.
68
74
  */
69
- private _injectCookies;
75
+ private injectCookies;
70
76
  }
71
77
  /**
72
78
  * Establish an HTTP/1.1 connection over an existing transport.
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,YAAY,EACf,MAAM,YAAY,CAAC;AAKpB,oCAAoC;AACpC,qBAAa,mBAAoB,YAAW,eAAe;IAqBnD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IApB7B,SAAgB,EAAE,EAAE,iBAAiB,CAAC;IAC/B,KAAK,EAAE,oBAAoB,CAAqB;IAEvD;;;OAGG;IACH,OAAO,CAAC,OAAO,CAAiC;IAEhD,mEAAmE;IACnE,OAAO,CAAC,YAAY,CAAyC;IAE7D,kFAAkF;IAClF,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