@browsercore/http1 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,106 @@
1
+ /**
2
+ * HTTP redirect following — protocol-level capability for @browsercore/http1.
3
+ *
4
+ * Design note: this logic is intentionally a STANDABLE exported function and is
5
+ * NOT wired into {@link Http1ConnectionImpl.request}. The @browsercore/fetch
6
+ * package implements its own redirect following (and connection-pool migration
7
+ * across origins) in `src/client.ts`. Auto-following here would double-follow
8
+ * against fetch. Instead, `followRedirects` gives a clean, tested capability
9
+ * that fetch (or any caller) can reuse, without changing current fetch behavior.
10
+ *
11
+ * Method/body rewrite follows RFC 7231:
12
+ * - 303 See Other -> GET, body stripped.
13
+ * - 307/308 -> method + body preserved.
14
+ * - 301/302 -> method + body preserved (RFC-correct; browsers
15
+ * historically GET-ify, but the spec does not).
16
+ */
17
+ import { RedirectLimitError } from "./errors.js";
18
+ /** Status codes that trigger redirect handling. */
19
+ export const REDIRECT_STATUS_CODES = [301, 302, 303, 307, 308];
20
+ /** Whether `status` is one of the redirect-triggering status codes. */
21
+ export function isRedirectStatus(status) {
22
+ return REDIRECT_STATUS_CODES.includes(status);
23
+ }
24
+ /**
25
+ * Resolve a possibly-relative `Location` header against the current absolute
26
+ * URL. A Location with its own scheme is returned as-is.
27
+ */
28
+ export function resolveRedirectUrl(currentUrl, location) {
29
+ return new URL(location, currentUrl).toString();
30
+ }
31
+ /** Project an absolute URL back onto the wire request target (path + query). */
32
+ function requestTarget(url) {
33
+ const parsed = new URL(url);
34
+ return `${parsed.pathname}${parsed.search}`;
35
+ }
36
+ /**
37
+ * Build the request for the next hop of a redirect, rewriting method/body and
38
+ * the `host` header per the status code.
39
+ */
40
+ function buildRedirectRequest(req, status, nextUrl) {
41
+ const headers = new Map(req.headers);
42
+ headers.set("host", new URL(nextUrl).host);
43
+ if (status === 303) {
44
+ // See Other: drop the body and any body-framing headers, switch to GET.
45
+ headers.delete("content-length");
46
+ headers.delete("transfer-encoding");
47
+ headers.delete("content-type");
48
+ return {
49
+ method: "GET",
50
+ url: requestTarget(nextUrl),
51
+ headers,
52
+ body: { kind: "empty" },
53
+ };
54
+ }
55
+ return {
56
+ ...req,
57
+ url: requestTarget(nextUrl),
58
+ headers,
59
+ };
60
+ }
61
+ /**
62
+ * Follow redirects for a request, returning the final response.
63
+ *
64
+ * The first request is dispatched as given; each redirect response is resolved
65
+ * against the URL of the request that produced it. The chain stops at the
66
+ * first non-redirect response, a redirect with no `Location`, or when the
67
+ * limit / a loop is detected.
68
+ *
69
+ * @param conn The connection to dispatch each hop on (same-origin redirects).
70
+ * @param req The initial request (carries the request target in `url`).
71
+ * @param currentUrl The absolute URL `req` was sent to — needed because
72
+ * `HttpRequest.url` is only the request target, not a full URL.
73
+ * @throws {RedirectLimitError} on exceeding `maxRedirects` or a repeated URL.
74
+ */
75
+ export async function followRedirects(conn, req, currentUrl, options = {}) {
76
+ const maxRedirects = options.maxRedirects ?? 20;
77
+ // trail[0] is the starting URL; each followed URL is appended. Used both
78
+ // for loop detection and as the debug trail in the error.
79
+ const trail = [currentUrl];
80
+ let url = currentUrl;
81
+ let request = req;
82
+ let response = await conn.request(request);
83
+ while (isRedirectStatus(response.statusCode)) {
84
+ // We've followed `trail.length - 1` redirects so far. Following one
85
+ // more would exceed the limit.
86
+ if (trail.length > maxRedirects) {
87
+ throw new RedirectLimitError(maxRedirects, trail);
88
+ }
89
+ const location = response.headers.get("location");
90
+ if (location === undefined) {
91
+ // No Location header — nothing to follow. Return as-is.
92
+ return response;
93
+ }
94
+ const nextUrl = resolveRedirectUrl(url, location);
95
+ // Loop detection: a URL we've already visited.
96
+ if (trail.includes(nextUrl)) {
97
+ throw new RedirectLimitError(maxRedirects, [...trail, nextUrl]);
98
+ }
99
+ trail.push(nextUrl);
100
+ url = nextUrl;
101
+ request = buildRedirectRequest(request, response.statusCode, url);
102
+ response = await conn.request(request);
103
+ }
104
+ return response;
105
+ }
106
+ //# s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I,kBAAkB,CAAC,YAAY,EAAE,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;QACpE,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,GAAG,GAAG,OAAO,CAAC;QACd,OAAO,GAAG,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAClE,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Domain types for @browsercore/http1.
3
+ *
4
+ * HTTP/1.1 client over any duplex byte stream. This package owns NO knowledge
5
+ * of TLS, TCP, or DNS — it composes exclusively over `@browsercore/transport`.
6
+ */
7
+ import type { Transport } from "@browsercore/transport";
8
+ /** Branded HTTP/1.1 connection identifier. */
9
+ export type Http1ConnectionId = string & {
10
+ __brand: "Http1ConnectionId";
11
+ };
12
+ /** HTTP methods this client supports. Literal union — never bare `string`. */
13
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT";
14
+ /** What kind of body a request carries — makes the absent body unrepresentable. */
15
+ export type HttpBodyKind = {
16
+ readonly kind: "empty";
17
+ } | {
18
+ readonly kind: "bytes";
19
+ readonly data: Uint8Array;
20
+ } | {
21
+ readonly kind: "stream";
22
+ readonly stream: AsyncIterable<Uint8Array>;
23
+ };
24
+ /** A fully-serializable HTTP/1.1 request. */
25
+ export interface HttpRequest {
26
+ readonly method: HttpMethod;
27
+ readonly url: string;
28
+ /** Headers are case-insensitive once serialized — stored as a ReadonlyMap. */
29
+ readonly headers: ReadonlyMap<string, string>;
30
+ readonly body: HttpBodyKind;
31
+ }
32
+ /** A parsed HTTP/1.1 response. */
33
+ export interface HttpResponse {
34
+ readonly statusCode: number;
35
+ readonly statusText: string;
36
+ readonly headers: ReadonlyMap<string, string>;
37
+ readonly body: Uint8Array;
38
+ }
39
+ /** Why an HTTP/1.1 connection was closed. */
40
+ export type Http1CloseReason = {
41
+ readonly kind: "client_close";
42
+ } | {
43
+ readonly kind: "remote_close";
44
+ } | {
45
+ readonly kind: "error";
46
+ readonly error: Error;
47
+ } | {
48
+ readonly kind: "redirect_jump";
49
+ readonly to: string;
50
+ };
51
+ /** Lifecycle state of an HTTP/1.1 connection. */
52
+ export type Http1ConnectionState = {
53
+ readonly state: "idle";
54
+ } | {
55
+ readonly state: "in_flight";
56
+ readonly pending: number;
57
+ } | {
58
+ readonly state: "closing";
59
+ } | {
60
+ readonly state: "closed";
61
+ readonly reason: Http1CloseReason;
62
+ };
63
+ /** Public contract for an HTTP/1.1 connection. */
64
+ export interface Http1Connection {
65
+ /** Opaque identifier for logging / correlation. */
66
+ readonly id: Http1ConnectionId;
67
+ /** Current lifecycle state. */
68
+ readonly state: Http1ConnectionState;
69
+ /**
70
+ * Send a request and await the full response. Resolves when the response
71
+ * headers + body have been read and decoded (per content-encoding).
72
+ */
73
+ request(req: HttpRequest): Promise<HttpResponse>;
74
+ /** Gracefully close the connection. Resolves once no requests are in flight. */
75
+ close(reason?: Http1CloseReason): Promise<void>;
76
+ }
77
+ /**
78
+ * Cookie-jar integration seam.
79
+ *
80
+ * http1 does NOT own cookie storage — the @browsercore/fetch cookie jar does. This
81
+ * interface is the seam: a caller that wants cookies injected / collected
82
+ * supplies an implementation. When absent, requests pass through unchanged.
83
+ *
84
+ * `addCookies` returns either a full header map to merge in, or a single
85
+ * `Cookie` header value as a bare string.
86
+ */
87
+ export interface CookieInterceptor {
88
+ /** Return headers to inject (e.g. `Cookie`) for the given request URL. */
89
+ readonly addCookies?: (url: CookieUrl) => Map<string, string> | string;
90
+ /** Store any `Set-Cookie` headers received for the given response URL. */
91
+ readonly storeCookies?: (url: CookieUrl, setCookieHeaders: string[]) => void;
92
+ }
93
+ /** The subset of URL info a cookie interceptor needs to match/store. */
94
+ export interface CookieUrl {
95
+ /** Host (no port) to match cookies against. */
96
+ readonly host: string;
97
+ /** Path to match cookies against. */
98
+ readonly path: string;
99
+ /** Protocol, e.g. `"http:"` or `"https:"`. */
100
+ readonly protocol: string;
101
+ }
102
+ /** Options for {@link connectHttp1}. */
103
+ export interface Http1Options {
104
+ /** The underlying byte-stream transport (already connected). */
105
+ readonly transport: Transport;
106
+ /**
107
+ * Maximum redirects to follow before raising {@link RedirectLimitError}.
108
+ * Default 10. Note: http1 does NOT auto-follow redirects — this is consumed
109
+ * by the standalone {@link followRedirects} helper. See src/redirect.ts.
110
+ */
111
+ readonly maxRedirects?: number;
112
+ /**
113
+ * Whether to follow 3xx redirects at all. Default true. Note: http1 does
114
+ * NOT auto-follow redirects — this is consumed by the standalone
115
+ * {@link followRedirects} helper. See src/redirect.ts.
116
+ */
117
+ readonly followRedirects?: boolean;
118
+ /** Override the default headers encoder (for testing / exotic encodings). */
119
+ readonly headersEncoder?: "ascii" | "utf8";
120
+ /**
121
+ * Optional cookie-jar seam. When present, `addCookies` is called before
122
+ * serializing each request and `storeCookies` after parsing each response.
123
+ * http1 performs no cookie storage of its own.
124
+ */
125
+ readonly cookieInterceptor?: CookieInterceptor;
126
+ }
127
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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;AAExD,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,mFAAmF;AACnF,MAAM,M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AAgE;IAChE,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;CAClD"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Domain types for @browsercore/http1.
3
+ *
4
+ * HTTP/1.1 client over any duplex byte stream. This package owns NO knowledge
5
+ * of TLS, TCP, or DNS — it composes exclusively over `@browsercore/transport`.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Small shared helpers for @browsercore/http1.
3
+ *
4
+ * Kept dependency-free so every package can copy the pattern without pulling in
5
+ * cross-package imports.
6
+ */
7
+ import type { Http1ConnectionId } from "./types.js";
8
+ /**
9
+ * Exhaustiveness check for `switch`/`if-else` over discriminated unions.
10
+ * Call in the `default` branch: `default: assertNever(x)`.
11
+ * Adding a new union member forces every handler to compile-error until handled.
12
+ */
13
+ export declare function assertNever(x: never): never;
14
+ /** Generate a branded HTTP/1.1 connection id. */
15
+ export declare function createId(prefix: string): Http1ConnectionId;
16
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;GAIG;AAEH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAE3C;AAED,iDAAiD;AACjD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAE1D"}
package/dist/utils.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Small shared helpers for @browsercore/http1.
3
+ *
4
+ * Kept dependency-free so every package can copy the pattern without pulling in
5
+ * cross-package imports.
6
+ */
7
+ /**
8
+ * Exhaustiveness check for `switch`/`if-else` over discriminated unions.
9
+ * Call in the `default` branch: `default: assertNever(x)`.
10
+ * Adding a new union member forces every handler to compile-error until handled.
11
+ */
12
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
+ export function assertNever(x) {
14
+ throw new Error(`Unexpected value: ${JSON.stringify(x)}`);
15
+ }
16
+ /** Generate a branded HTTP/1.1 connection id. */
17
+ export function createId(prefix) {
18
+ return `${prefix}_${Date.now().toString(36)}_${Math.floor(Math.random() * 1e6).toString(36)}`;
19
+ }
20
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;GAIG;AACH,6DAA6D;AAC7D,MAAM,UAAU,WAAW,CAAC,CAAQ;IAChC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,QAAQ,CAAC,MAAc;IACnC,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAuB,CAAC;AACvH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@browsercore/http1",
3
+ "version": "0.1.0",
4
+ "description": "HTTP/1.1 client over any duplex byte stream. No knowledge of TLS or TCP — only the protocol.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/jverneuer/browsercore-http1.git"
8
+ },
9
+ "homepage": "https://github.com/jverneuer/browsercore-http1#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/jverneuer/browsercore-http1/issues"
12
+ },
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": ["dist", "LICENSE", "README.md"],
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "registry": "https://registry.npmjs.org/"
27
+ },
28
+ "scripts": {
29
+ "clean": "rm -rf dist",
30
+ "build": "tsc -p tsconfig.build.json",
31
+ "prepublishOnly": "npm run clean && npm run build",
32
+ "typecheck": "tsc -p tsconfig.json --noEmit",
33
+ "test": "vitest run"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^20.14.0",
37
+ "typescript": "^5.6.3",
38
+ "vitest": "^2.1.8"
39
+ },
40
+ "dependencies": {
41
+ "@browsercore/transport": "^0.1.0"
42
+ },
43
+ "engines": {
44
+ "node": ">=24.0.0"
45
+ }
46
+ }