@ngrok/app-server 0.3.5 → 0.4.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.
- package/README.md +41 -10
- package/dist/cli.js +3 -3
- package/dist/client.js +1 -1
- package/dist/{compress-CO0Nwc8x.js → compress-Cp5NfXCC.js} +138 -29
- package/dist/compress-Cp5NfXCC.js.map +1 -0
- package/dist/{create-server-C_90R50y.js → create-server-C63luLkn.js} +71 -30
- package/dist/create-server-C63luLkn.js.map +1 -0
- package/dist/{create-server-kxyhCdhv.d.ts → create-server-DKJ0wASH.d.ts} +33 -13
- package/dist/{entry-65IESBSA.js → entry-BSbsQ_kq.js} +13 -5
- package/dist/entry-BSbsQ_kq.js.map +1 -0
- package/dist/{entry-CNL4OsEn.d.ts → entry-C9bBcYeP.d.ts} +3 -3
- package/dist/index.d.ts +18 -5
- package/dist/index.js +6 -6
- package/dist/{load-entry-svVuPIFq.js → load-entry-DgZyPtoD.js} +4 -4
- package/dist/{load-entry-svVuPIFq.js.map → load-entry-DgZyPtoD.js.map} +1 -1
- package/dist/log-CW_g1pWk.js +304 -0
- package/dist/log-CW_g1pWk.js.map +1 -0
- package/dist/{node-Bgzhwix0.js → node-DBwgrye_.js} +2 -2
- package/dist/{node-Bgzhwix0.js.map → node-DBwgrye_.js.map} +1 -1
- package/dist/{node-DFI5TjTk.js → node-DiMwdTOC.js} +4 -4
- package/dist/{node-DFI5TjTk.js.map → node-DiMwdTOC.js.map} +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +2 -2
- package/dist/react-router.d.ts +2 -2
- package/dist/react-router.js +3 -4
- package/dist/react-router.js.map +1 -1
- package/dist/request-context-BdAH1D-2.js +80 -0
- package/dist/request-context-BdAH1D-2.js.map +1 -0
- package/dist/{response-edge-D3CAjukJ.js → response-edge-7eUl2ewl.js} +3 -3
- package/dist/response-edge-7eUl2ewl.js.map +1 -0
- package/dist/{response-writer-5SOKsW3C.js → response-writer-CLtCseu5.js} +3 -3
- package/dist/{response-writer-5SOKsW3C.js.map → response-writer-CLtCseu5.js.map} +1 -1
- package/dist/{serve-DKoZxZj4.js → serve-DCaIBTM-.js} +2 -2
- package/dist/{serve-DKoZxZj4.js.map → serve-DCaIBTM-.js.map} +1 -1
- package/dist/{start-3_WlRLdK.js → start-D2IVWkow.js} +29 -13
- package/dist/start-D2IVWkow.js.map +1 -0
- package/dist/tanstack-start.d.ts +2 -2
- package/dist/tanstack-start.js +1 -1
- package/dist/{tcp-CKMCT9RP.js → tcp-B8aFGQRB.js} +2 -2
- package/dist/{tcp-CKMCT9RP.js.map → tcp-B8aFGQRB.js.map} +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +4 -4
- package/dist/{trailing-slash-DeOUxMYo.d.ts → trailing-slash-D_52DJaQ.d.ts} +2 -2
- package/dist/{types-BKJxtIuj.d.ts → types-C_I3i62n.d.ts} +32 -4
- package/dist/vercel.d.ts +2 -2
- package/dist/vercel.js +4 -4
- package/package.json +1 -1
- package/dist/compress-CO0Nwc8x.js.map +0 -1
- package/dist/create-server-C_90R50y.js.map +0 -1
- package/dist/entry-65IESBSA.js.map +0 -1
- package/dist/log-C8LGQ23s.js +0 -149
- package/dist/log-C8LGQ23s.js.map +0 -1
- package/dist/request-context-BtQ87VYb.js +0 -40
- package/dist/request-context-BtQ87VYb.js.map +0 -1
- package/dist/response-edge-D3CAjukJ.js.map +0 -1
- package/dist/start-3_WlRLdK.js.map +0 -1
package/README.md
CHANGED
|
@@ -274,7 +274,7 @@ The function differs from a long-lived process:
|
|
|
274
274
|
1. `health()`: the liveness and readiness probes at `/livez` and `/readyz`. A probe skips the access log. `defaultPlugins({ health })` changes them, and `false` turns them off. See [Health checks](#health-checks).
|
|
275
275
|
2. `requestId()`: reuses a valid incoming `X-Request-Id`, else makes a UUID, and echoes it.
|
|
276
276
|
3. `accessLog({ redactQuery })`: one line per request when the response ends, for the response that leaves the server, with Datadog standard attributes (`http.status_code`, `network.bytes_written`, `duration` in nanoseconds). Query values are `REDACTED` by default. A 5xx line has the level `error`, and each other line has the level `info`. With React Router, a line for a request that React Router answers has the route pattern that it matched as `http.route`, such as `/domains/:domainId`. A prerendered page that the server sends from its file has no `http.route`. In development, a request that Vite answers, such as a source module or `/@vite/client`, gets no line. A request of the `vercel` build's check of the CDN pages gets no line.
|
|
277
|
-
4. `streamingCompress()`: brotli or gzip that flushes after each chunk. A client gets brotli, at quality 4, when its `Accept-Encoding` ranks `br` at least as high as `gzip`. For HTML, brotli at quality 4 is smaller than gzip, for the same CPU time. For example, a page of 149 KiB in 10 chunks takes 0.60 ms and 7.7 KiB as brotli, and 0.68 ms and 10.6 KiB as gzip, on an Apple M3 Max. The `compression` middleware of Express also uses quality 4.
|
|
277
|
+
4. `streamingCompress()`: brotli or gzip that flushes after each chunk. A client gets brotli, at quality 4, when its `Accept-Encoding` ranks `br` at least as high as `gzip`. For HTML, brotli at quality 4 is smaller than gzip, for the same CPU time. For example, a page of 149 KiB in 10 chunks takes 0.60 ms and 7.7 KiB as brotli, and 0.68 ms and 10.6 KiB as gzip, on an Apple M3 Max. The `compression` middleware of Express also uses quality 4. On the node host, brotli holds the start of a body to pick its window. A body that ends within 256 KiB gets a window of 256 KiB, in one zlib call. A longer body gets the default window of 4 MiB, so it can use a repeat that is more than 256 KiB back. Why not 4 MiB for each body: Node.js tells V8 the full window of each open encoder, and under load V8 then runs a full garbage collection for every few responses. When the body waits for its next chunk first, for one turn of the event loop, the stream sends what it holds with the 256 KiB window. So a page shell that waits for slow data, such as a React `<Suspense>` boundary, still goes out at once. Chunks that the body has queued together go out as one, up to 64 KiB, so a rendered page costs fewer flushes. For example, a rendered page of 19 KB that the body queues at once costs one zlib call, not three. When the body ends by the time the stream finishes its last chunk, that chunk and the end of the stream go out together. On the node host, a body that ends with its first chunk, up to 64 KiB for gzip and 256 KiB for brotli, uses a zlib stream from a pool, so a small page costs no new zlib stream. Each encoding keeps up to 16 streams between responses. The gzip streams hold about 4.3 MiB in all. A gzip stream takes only such a body, and only one at least as long as each earlier body of that stream, so the gzip bytes of a body depend on that body alone. A reset gives a brotli stream a new encoder, so its bytes also depend on the body alone. On Bun and Deno, each brotli body gets a new stream, because a reset there loses the quality or gives no bytes. It skips encoded, partial, and `no-transform` responses, and a body under 1,024 bytes: by its `Content-Length`, or a body from a string. It adds `Accept-Encoding` to `Vary` only on a compressible type, the same types that get a copy from the build. A static file with a compressed copy from the build gets that copy, and this plugin skips it. It follows the `q` values of `Accept-Encoding`, and `q=0` refuses an encoding. The host gives the streams. On a host with neither, the plugin does nothing.
|
|
278
278
|
5. `securityHeaders()`: safe default security headers on each response, prerendered pages included. `defaultPlugins({ securityHeaders })` changes them, and `false` turns them off. See [Security headers](#security-headers).
|
|
279
279
|
6. `bodyLimit({ maxBytes })`: a 413 for a request body over `defaultPlugins({ bodyLimit })`, 10 mebibytes (MiB) by default. `false` turns it off. A `Content-Length` that is too large gets the 413 before the app runs. A streamed body errors when it passes the limit. When the app reads the body before it answers, the response becomes a 413. When the app streams the body into its response, the response stream errors. A `bodyLimit` that is not a whole number of 0 or more stops startup. The body streams. The plugin does not read it into memory.
|
|
280
280
|
7. The plugins of the named options. They see every response, prerendered pages included:
|
|
@@ -403,7 +403,7 @@ In development, `app-server start` sends the same policy. A rendered page gets a
|
|
|
403
403
|
createServer({
|
|
404
404
|
plugins: defaultPlugins({
|
|
405
405
|
contentSecurityPolicy: {
|
|
406
|
-
policy: (scriptSrc) => `script-src ${scriptSrc}; object-src 'none'; base-uri 'none'`,
|
|
406
|
+
policy: ({ scriptSrc }) => `script-src ${scriptSrc}; object-src 'none'; base-uri 'none'`,
|
|
407
407
|
},
|
|
408
408
|
}),
|
|
409
409
|
});
|
|
@@ -682,7 +682,9 @@ The default twin is the path with no trailing slash plus `.md`, and `/index.md`
|
|
|
682
682
|
A different mapping goes in `twinOf`. Its path follows the same rules as a request path, and it can give a twin to a request that `rewrite` changes:
|
|
683
683
|
|
|
684
684
|
```ts
|
|
685
|
-
prerendered({
|
|
685
|
+
prerendered({
|
|
686
|
+
markdownTwins: { twinOf: ({ path }) => (path === "/" ? "/llms.md" : `${path}.md`) },
|
|
687
|
+
});
|
|
686
688
|
```
|
|
687
689
|
|
|
688
690
|
`twinOf` also gets the request's Hono context, the same as `rewrite`. If it gives `undefined`, the request gets no twin, and the answer gets no `Vary: Accept` and no `Link`.
|
|
@@ -753,20 +755,48 @@ Pass a sink to use your own format. Attribute names are flat and dotted:
|
|
|
753
755
|
```ts
|
|
754
756
|
createServer({
|
|
755
757
|
logger: {
|
|
756
|
-
log: (level, message, attributes) => mySlogger[level](message, attributes),
|
|
758
|
+
log: ({ level, message, attributes }) => mySlogger[level](message, attributes),
|
|
757
759
|
},
|
|
758
760
|
});
|
|
759
761
|
```
|
|
760
762
|
|
|
761
|
-
The default is `jsonSink()`: one JSON object per line on standard output (stdout). It writes the lines of one event-loop turn in one write, at the end of the turn. Each line still reaches stdout before the process exits, and before the vercel handler returns.
|
|
763
|
+
The default is `jsonSink()`: one JSON object per line on standard output (stdout). It writes the lines of one event-loop turn in one write, at the end of the turn. Each line still reaches stdout before the process exits, and before the vercel handler returns. `jsonSink()` writes a bigint as a string, such as `"1n"`, and a cycle as `"[Circular]"`. A line whose attributes have no JSON, such as a value whose `toJSON` throws, goes out with `log.error` in place of its attributes, so `jsonSink()` never throws for its attributes. Like `JSON.stringify`, it writes a `Map` or a `Set` as `{}`, so convert it first, such as with `Object.fromEntries(map)`.
|
|
764
|
+
|
|
765
|
+
In server code, `logger()` gives the logger of the request that runs. Its lines carry the request ID, method, and path, and these fields win over a field of the same name that you give. Outside a request, such as at module load or in a prerender pass, `logger()` writes to the sink and hooks of the last `createServer` call, else to `jsonSink()`:
|
|
766
|
+
|
|
767
|
+
```ts
|
|
768
|
+
import { logger } from "@ngrok/app-server";
|
|
769
|
+
|
|
770
|
+
export async function loader() {
|
|
771
|
+
logger().info("loading", { "usr.id": userId });
|
|
772
|
+
}
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
An attribute whose value is an `Error` becomes dotted fields under its name: `kind`, `message`, `stack`, each own field, such as `code`, and the `cause` chain as `<name>.cause.*`. An `AggregateError` adds its members as `<name>.errors`. An error with `toJSON` gives its own fields from it. The server's own error lines, such as `unhandled error`, use the same fields:
|
|
776
|
+
|
|
777
|
+
```ts
|
|
778
|
+
logger().error("payment failed", { error });
|
|
779
|
+
// {"message":"payment failed","error.kind":"TypeError","error.message":"…","error.stack":"…","error.cause.kind":"Error","error.cause.code":"ECONNRESET",…}
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
The `log` option changes each line of the server and of `logger()` before it goes to the sink. `attributes` gets the attributes after the server flattens each error. `error` gets each error, its attribute name, and its default fields, and gives the fields to write:
|
|
783
|
+
|
|
784
|
+
```ts
|
|
785
|
+
createServer({
|
|
786
|
+
log: {
|
|
787
|
+
attributes: ({ attributes }) => ({ ...attributes, "usr.email": undefined }),
|
|
788
|
+
error: ({ prefix, fields }) => ({ ...fields, [`${prefix}.stack`]: undefined }),
|
|
789
|
+
},
|
|
790
|
+
});
|
|
791
|
+
```
|
|
762
792
|
|
|
763
|
-
|
|
793
|
+
`requestContext()` gives the request ID, the logger, the CSP nonce, and the client address of the request that runs. It works with each framework. It gives `undefined` outside a server request:
|
|
764
794
|
|
|
765
795
|
```ts
|
|
766
796
|
import { requestContext } from "@ngrok/app-server";
|
|
767
797
|
|
|
768
798
|
export async function loader() {
|
|
769
|
-
requestContext()?.
|
|
799
|
+
const requestId = requestContext()?.requestId;
|
|
770
800
|
}
|
|
771
801
|
```
|
|
772
802
|
|
|
@@ -782,14 +812,14 @@ export async function loader({ context }: Route.LoaderArgs) {
|
|
|
782
812
|
|
|
783
813
|
A request with a valid W3C `traceparent` header logs `trace_id` and `span_id` on each line. `requestId({ datadogTraceIds: true })` also logs `dd.trace_id` and `dd.span_id`, the lower 64 bits in decimal, so Datadog connects each line to its trace.
|
|
784
814
|
|
|
785
|
-
`accessLog({ attributes })` adds the app's own attributes to each request line. The callback runs when the line goes out. It gets the context and what went out
|
|
815
|
+
`accessLog({ attributes })` adds the app's own attributes to each request line. The callback runs when the line goes out. It gets `{ context, sent }`: the request's context, and what went out as `status`, `headers`, `bytes`, and `aborted`. Read a response header from `sent.headers`, not from `context.res`: `sent.headers` has the headers that went out on each runtime, after the header hooks, and `context.res` can lack them. On Node.js and Vercel, `sent.headers` also has the headers that the listener adds, such as `Content-Length`. `accessLog({ serverTiming: true })` sets `Server-Timing: app;dur=<ms>` on each HTML document: the time until the response headers were ready.
|
|
786
816
|
|
|
787
817
|
```ts
|
|
788
818
|
defaultPlugins({
|
|
789
819
|
requestId: { datadogTraceIds: true },
|
|
790
820
|
accessLog: {
|
|
791
|
-
attributes: (
|
|
792
|
-
"usr.id":
|
|
821
|
+
attributes: ({ context, sent }) => ({
|
|
822
|
+
"usr.id": context.get("userId"),
|
|
793
823
|
"http.response.cache_control": sent.headers.get("Cache-Control"),
|
|
794
824
|
}),
|
|
795
825
|
},
|
|
@@ -907,6 +937,7 @@ A framework adapter or a host adapter is two small objects. A third-party adapte
|
|
|
907
937
|
|
|
908
938
|
- `plugins`: default `defaultPlugins()`.
|
|
909
939
|
- `logger`: default `jsonSink()`.
|
|
940
|
+
- `log`: hooks that change each log line: `attributes` and `error`. See [Logs](#logs).
|
|
910
941
|
- `listeners`: default the host's listeners. A listener decides how connections arrive. On the node host, the default is `[tcp()]` from `@ngrok/app-server/node`. `tcp()` uses `node:http`, `Bun.serve`, or `Deno.serve`.
|
|
911
942
|
- `trustForwardedProto`: read the scheme from `X-Forwarded-Proto`. Set it only behind a proxy that overwrites the header. Default `false`. The server passes it to each listener as `start(fetch, { trustForwardedProto })`, so the node listener on Node.js builds each request with that scheme and copies none. For a listener that ignores it, the server copies each request to change its scheme. For a build with no `server.ts`, set `TRUST_FORWARDED_PROTO=1`. TanStack Start compares a server function call's `Origin` with the request URL when the browser sends no `Sec-Fetch-Site`, so set this option behind a proxy that ends TLS.
|
|
912
943
|
- `trustedProxyHops`: how many proxies in front of the server add to `X-Forwarded-For`, such as `1` behind the ngrok edge. With N, the client address is the Nth address from the right of that header. The access log and `requestContext()?.clientAddress` use it. Default `0`, the address of the socket. Set it only to the number of proxies that you run, else a client can spoof its address. For a build with no `server.ts`, set `TRUSTED_PROXY_HOPS`.
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as parsePort } from "./tcp-
|
|
2
|
+
import { t as parsePort } from "./tcp-B8aFGQRB.js";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
|
|
@@ -42,12 +42,12 @@ try {
|
|
|
42
42
|
if (args?.help === true) process.stdout.write(`${USAGE}\n`);
|
|
43
43
|
else if (args?.command === "start") {
|
|
44
44
|
process.env.NODE_ENV ??= "development";
|
|
45
|
-
const { start } = await import("./start-
|
|
45
|
+
const { start } = await import("./start-D2IVWkow.js");
|
|
46
46
|
await start();
|
|
47
47
|
} else if (args?.command === "serve") {
|
|
48
48
|
process.env.NODE_ENV ??= "production";
|
|
49
49
|
if (typeof process.setSourceMapsEnabled === "function") process.setSourceMapsEnabled(true);
|
|
50
|
-
const { serve } = await import("./serve-
|
|
50
|
+
const { serve } = await import("./serve-DCaIBTM-.js");
|
|
51
51
|
await serve({ buildPath: args.buildPath });
|
|
52
52
|
} else if (args != null) fail(args.command == null ? "Give a command." : `Unknown command: ${args.command}.`);
|
|
53
53
|
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as requestContext } from "./request-context-BdAH1D-2.js";
|
|
2
2
|
import { n as staleBuildTanStack, r as documentNonce, t as staleBuildReactRouter } from "./stale-build-navigation-rg5xxmTr.js";
|
|
3
3
|
|
|
4
4
|
// src/client/csp-nonce.ts
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setImmediate } from "node:timers";
|
|
1
2
|
import { brotliCompressSync, constants, crc32, createBrotliCompress, createDeflateRaw, createGzip } from "node:zlib";
|
|
2
3
|
|
|
3
4
|
// src/node/compress.ts
|
|
@@ -7,7 +8,11 @@ import { brotliCompressSync, constants, crc32, createBrotliCompress, createDefla
|
|
|
7
8
|
* and a field costs less than a `WeakMap` entry for each response.
|
|
8
9
|
*/
|
|
9
10
|
var ZlibBody = class extends ReadableStream {
|
|
10
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Whether the next chunk waits only on zlib, because the source gave the
|
|
13
|
+
* bytes already. It stays set while a brotli stream holds the start of a
|
|
14
|
+
* body, which ends when the source waits.
|
|
15
|
+
*/
|
|
11
16
|
busy = false;
|
|
12
17
|
};
|
|
13
18
|
/**
|
|
@@ -51,11 +56,11 @@ const EMPTY_MEMBER = Buffer.concat([HEADER, Buffer.from([
|
|
|
51
56
|
0
|
|
52
57
|
])]);
|
|
53
58
|
/**
|
|
54
|
-
* The largest body that a pooled gzip
|
|
55
|
-
*
|
|
56
|
-
*
|
|
59
|
+
* The largest body that a pooled gzip stream compresses. Why a limit: above
|
|
60
|
+
* about 64 KiB, the CRC-32 of a gzip body on the main thread costs more than
|
|
61
|
+
* a new zlib stream does.
|
|
57
62
|
*/
|
|
58
|
-
const
|
|
63
|
+
const GZIP_POOLED_MAX_BYTES = 65536;
|
|
59
64
|
/** The most zlib streams that wait for a body in each pool. Why a limit: an idle deflate stream keeps about 276 KiB of zlib state. */
|
|
60
65
|
const MAX_IDLE = 16;
|
|
61
66
|
function ignore() {}
|
|
@@ -95,18 +100,29 @@ const DEFLATE_POOL = {
|
|
|
95
100
|
*/
|
|
96
101
|
const BROTLI_QUALITY = 4;
|
|
97
102
|
/**
|
|
98
|
-
* The base-2 logarithm of the brotli window
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
+
* The base-2 logarithm of the brotli window of a body up to
|
|
104
|
+
* {@link BROTLI_HOLD_BYTES}, 256 KiB. Why not the default of 22 (4 MiB):
|
|
105
|
+
* Node.js tells V8 the full size of each encoder's ring buffer as external
|
|
106
|
+
* memory, and at 32 open encoders V8 then runs a full garbage collection for
|
|
107
|
+
* every few responses.
|
|
103
108
|
*/
|
|
104
109
|
const BROTLI_WINDOW_BITS = 18;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
/**
|
|
111
|
+
* The most bytes of a body that a brotli stream holds to pick the window: 256
|
|
112
|
+
* KiB for a body that ends within them, else the default of 4 MiB. Why: a
|
|
113
|
+
* stream has no length to pick from, and a repeat more than 256 KiB back costs
|
|
114
|
+
* a page of 2.5 MB 30% more bytes.
|
|
115
|
+
*/
|
|
116
|
+
const BROTLI_HOLD_BYTES = 2 ** BROTLI_WINDOW_BITS;
|
|
117
|
+
function brotliParams(windowBits) {
|
|
118
|
+
return {
|
|
119
|
+
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,
|
|
120
|
+
[constants.BROTLI_PARAM_QUALITY]: BROTLI_QUALITY,
|
|
121
|
+
[constants.BROTLI_PARAM_LGWIN]: windowBits
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const BROTLI_PARAMS = brotliParams(BROTLI_WINDOW_BITS);
|
|
125
|
+
const BROTLI_LARGE_PARAMS = brotliParams(constants.BROTLI_DEFAULT_WINDOW);
|
|
110
126
|
/**
|
|
111
127
|
* The brotli pool. Why not sized: a reset makes a new brotli encoder with the
|
|
112
128
|
* same parameters, so the output of a body never depends on an earlier one.
|
|
@@ -242,12 +258,26 @@ async function brotliOnce(value, use) {
|
|
|
242
258
|
return Buffer.concat(await compressOnce(BROTLI_POOL, value, use));
|
|
243
259
|
}
|
|
244
260
|
/**
|
|
261
|
+
* The most chunks that {@link zlibStream} holds. Why: a source that gives each
|
|
262
|
+
* chunk at once keeps the hold in one turn of the event loop, and 262,144
|
|
263
|
+
* chunks of 1 byte blocked it for 215 ms on an Apple M3 Max.
|
|
264
|
+
*/
|
|
265
|
+
const HOLD_MAX_CHUNKS = 1024;
|
|
266
|
+
function join(chunks, size) {
|
|
267
|
+
const [first] = chunks;
|
|
268
|
+
return chunks.length === 1 && first != null ? first : Buffer.concat(chunks, size);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
245
271
|
* Compresses a byte stream with `codec`. Each written chunk is readable at
|
|
246
272
|
* once. It reads the next source chunk only when the consumer pulls, so a
|
|
247
273
|
* slow client holds back the source. When the source ends by the time zlib
|
|
248
274
|
* finishes a chunk, that chunk and the end of the stream go out as one. Why:
|
|
249
275
|
* the host writes each chunk to the socket on its own, and a write costs more
|
|
250
276
|
* than its few bytes.
|
|
277
|
+
*
|
|
278
|
+
* With `codec.createLarge`, it first holds the body up to
|
|
279
|
+
* `codec.onceMaxBytes`, the end, or a wait of the source, and then writes
|
|
280
|
+
* what it holds.
|
|
251
281
|
*/
|
|
252
282
|
function zlibStream(source, codec) {
|
|
253
283
|
const reader = source.getReader();
|
|
@@ -261,6 +291,62 @@ function zlibStream(source, codec) {
|
|
|
261
291
|
/** The pooled zlib stream while it compresses the one chunk of a body. */
|
|
262
292
|
let pooled;
|
|
263
293
|
let started = false;
|
|
294
|
+
let canceled = false;
|
|
295
|
+
/** The source read that is still open after a hold. */
|
|
296
|
+
let pending;
|
|
297
|
+
/** The next source chunk with bytes, or the end. */
|
|
298
|
+
const read = async () => {
|
|
299
|
+
let chunk = await (pending ?? reader.read());
|
|
300
|
+
pending = void 0;
|
|
301
|
+
while (!chunk.done && chunk.value.byteLength === 0) chunk = await reader.read();
|
|
302
|
+
return chunk;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* `first` and the chunks after it, up to `max` bytes, until the source ends,
|
|
306
|
+
* gives an empty chunk, or leaves a read open for a turn of the event loop.
|
|
307
|
+
* Why stop on a wait: the source waits for data, such as a React
|
|
308
|
+
* `<Suspense>` boundary, and what it gave must reach the client now.
|
|
309
|
+
*/
|
|
310
|
+
const hold = async (first, max) => {
|
|
311
|
+
const parts = [first];
|
|
312
|
+
let size = first.byteLength;
|
|
313
|
+
/** Resolves at the end of this turn of the event loop. Why one for each turn: an immediate costs more than a read. */
|
|
314
|
+
let turn;
|
|
315
|
+
const endOfTurn = async () => new Promise((resolve) => {
|
|
316
|
+
setImmediate(() => {
|
|
317
|
+
turn = void 0;
|
|
318
|
+
resolve(void 0);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
while (size <= max && parts.length < HOLD_MAX_CHUNKS) {
|
|
322
|
+
pending ??= reader.read();
|
|
323
|
+
turn ??= endOfTurn();
|
|
324
|
+
const result = await Promise.race([pending, turn]);
|
|
325
|
+
if (result == null) break;
|
|
326
|
+
pending = void 0;
|
|
327
|
+
if (result.done) return {
|
|
328
|
+
value: join(parts, size),
|
|
329
|
+
done: true,
|
|
330
|
+
large: false
|
|
331
|
+
};
|
|
332
|
+
if (result.value.byteLength === 0) break;
|
|
333
|
+
if (size + result.value.byteLength > max) {
|
|
334
|
+
pending = Promise.resolve(result);
|
|
335
|
+
return {
|
|
336
|
+
value: join(parts, size),
|
|
337
|
+
done: false,
|
|
338
|
+
large: true
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
parts.push(result.value);
|
|
342
|
+
size += result.value.byteLength;
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
value: join(parts, size),
|
|
346
|
+
done: false,
|
|
347
|
+
large: size > max
|
|
348
|
+
};
|
|
349
|
+
};
|
|
264
350
|
/** The zlib output that waits for the next enqueue. */
|
|
265
351
|
let held = [];
|
|
266
352
|
let heldBytes = 0;
|
|
@@ -271,8 +357,8 @@ function zlibStream(source, codec) {
|
|
|
271
357
|
held = [];
|
|
272
358
|
heldBytes = 0;
|
|
273
359
|
};
|
|
274
|
-
const startZlib = (body, controller) => {
|
|
275
|
-
const created =
|
|
360
|
+
const startZlib = (body, controller, create) => {
|
|
361
|
+
const created = create();
|
|
276
362
|
created.on("data", (chunk) => {
|
|
277
363
|
held.push(chunk);
|
|
278
364
|
heldBytes += chunk.byteLength;
|
|
@@ -292,8 +378,9 @@ function zlibStream(source, codec) {
|
|
|
292
378
|
const stream = new ZlibBody({
|
|
293
379
|
async pull(controller) {
|
|
294
380
|
try {
|
|
295
|
-
|
|
296
|
-
|
|
381
|
+
const chunk = await read();
|
|
382
|
+
let create = codec.create;
|
|
383
|
+
let start;
|
|
297
384
|
if (!started) {
|
|
298
385
|
started = true;
|
|
299
386
|
if (chunk.done) {
|
|
@@ -303,8 +390,18 @@ function zlibStream(source, codec) {
|
|
|
303
390
|
}
|
|
304
391
|
stream.busy = true;
|
|
305
392
|
await Promise.resolve();
|
|
306
|
-
|
|
307
|
-
|
|
393
|
+
const { createLarge, onceMaxBytes } = codec;
|
|
394
|
+
start = ended || createLarge == null ? {
|
|
395
|
+
value: chunk.value,
|
|
396
|
+
done: ended,
|
|
397
|
+
large: chunk.value.byteLength > onceMaxBytes
|
|
398
|
+
} : await hold(chunk.value, onceMaxBytes);
|
|
399
|
+
if (canceled) {
|
|
400
|
+
stream.busy = false;
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (start.done && !start.large) {
|
|
404
|
+
const output = await codec.once(start.value, (each) => {
|
|
308
405
|
pooled = each;
|
|
309
406
|
});
|
|
310
407
|
stream.busy = false;
|
|
@@ -312,15 +409,17 @@ function zlibStream(source, codec) {
|
|
|
312
409
|
controller.close();
|
|
313
410
|
return;
|
|
314
411
|
}
|
|
412
|
+
if (createLarge != null && start.large) create = createLarge;
|
|
315
413
|
}
|
|
316
|
-
zlib ??= startZlib(stream, controller);
|
|
414
|
+
zlib ??= startZlib(stream, controller, create);
|
|
317
415
|
stream.busy = true;
|
|
318
416
|
if (chunk.done) {
|
|
319
417
|
zlib.end();
|
|
320
418
|
return;
|
|
321
419
|
}
|
|
322
|
-
await write(zlib, chunk.value);
|
|
323
|
-
|
|
420
|
+
await write(zlib, start?.value ?? chunk.value);
|
|
421
|
+
ended ||= start?.done === true;
|
|
422
|
+
if (ended && pending == null) {
|
|
324
423
|
zlib.end();
|
|
325
424
|
return;
|
|
326
425
|
}
|
|
@@ -333,6 +432,7 @@ function zlibStream(source, codec) {
|
|
|
333
432
|
}
|
|
334
433
|
},
|
|
335
434
|
async cancel(reason) {
|
|
435
|
+
canceled = true;
|
|
336
436
|
zlib?.destroy();
|
|
337
437
|
pooled?.stream.destroy();
|
|
338
438
|
return reader.cancel(reason);
|
|
@@ -343,7 +443,8 @@ function zlibStream(source, codec) {
|
|
|
343
443
|
const GZIP = {
|
|
344
444
|
create: () => createGzip({ flush: constants.Z_SYNC_FLUSH }),
|
|
345
445
|
empty: EMPTY_MEMBER,
|
|
346
|
-
once: gzipOnce
|
|
446
|
+
once: gzipOnce,
|
|
447
|
+
onceMaxBytes: GZIP_POOLED_MAX_BYTES
|
|
347
448
|
};
|
|
348
449
|
/**
|
|
349
450
|
* Gzips a byte stream. `Z_SYNC_FLUSH` makes each written chunk readable at
|
|
@@ -367,13 +468,21 @@ const BROTLI = {
|
|
|
367
468
|
params: BROTLI_PARAMS
|
|
368
469
|
}),
|
|
369
470
|
empty: brotliCompressSync(/* @__PURE__ */ new Uint8Array(), { params: BROTLI_PARAMS }),
|
|
370
|
-
once: brotliOnce
|
|
471
|
+
once: brotliOnce,
|
|
472
|
+
onceMaxBytes: BROTLI_HOLD_BYTES,
|
|
473
|
+
createLarge: () => createBrotliCompress({
|
|
474
|
+
flush: constants.BROTLI_OPERATION_FLUSH,
|
|
475
|
+
params: BROTLI_LARGE_PARAMS
|
|
476
|
+
})
|
|
371
477
|
};
|
|
372
478
|
/**
|
|
373
479
|
* Compresses a byte stream with brotli, quality 4. `BROTLI_OPERATION_FLUSH`
|
|
374
480
|
* makes each written chunk readable at once. It reads and ends as
|
|
375
|
-
* {@link gzipStream} does
|
|
376
|
-
*
|
|
481
|
+
* {@link gzipStream} does.
|
|
482
|
+
*
|
|
483
|
+
* It holds the start of a body to pick the window, as
|
|
484
|
+
* {@link BROTLI_HOLD_BYTES} says. When the source waits for its next chunk
|
|
485
|
+
* first, the stream sends what it holds with the 256 KiB window.
|
|
377
486
|
*
|
|
378
487
|
* @example
|
|
379
488
|
* new Response(brotliStream(response.body), response);
|
|
@@ -383,4 +492,4 @@ function brotliStream(source) {
|
|
|
383
492
|
}
|
|
384
493
|
|
|
385
494
|
export { gzipStream as n, waitsForZlib as r, brotliStream as t };
|
|
386
|
-
//# sourceMappingURL=compress-
|
|
495
|
+
//# sourceMappingURL=compress-Cp5NfXCC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compress-Cp5NfXCC.js","names":[],"sources":["../src/node/compress.ts"],"sourcesContent":["import type { Transform } from \"node:stream\";\nimport { setImmediate } from \"node:timers\";\nimport type { ReadResult } from \"../core/compression.js\";\nimport {\n\tbrotliCompressSync,\n\tconstants,\n\tcrc32,\n\tcreateBrotliCompress,\n\tcreateDeflateRaw,\n\tcreateGzip,\n} from \"node:zlib\";\n\n/**\n * A stream from {@link gzipStream} or {@link brotliStream}. Why a class: the\n * node response writer reads `busy` to hold the head for zlib's first chunk,\n * and a field costs less than a `WeakMap` entry for each response.\n */\nclass ZlibBody extends ReadableStream<Uint8Array> {\n\t/**\n\t * Whether the next chunk waits only on zlib, because the source gave the\n\t * bytes already. It stays set while a brotli stream holds the start of a\n\t * body, which ends when the source waits.\n\t */\n\tpublic busy = false;\n}\n\n/**\n * Whether the next chunk of `stream` waits only on zlib, because its source\n * gave the bytes already. It gives `undefined` for a stream that is not from\n * {@link gzipStream} or {@link brotliStream}.\n *\n * @example\n * waitsForZlib(gzipStream(source)); // => false, until the first read gives zlib a chunk\n */\nexport function waitsForZlib(stream: ReadableStream<Uint8Array>): boolean | undefined {\n\treturn stream instanceof ZlibBody ? stream.busy : undefined;\n}\n\n/**\n * The gzip header (RFC 1952): the magic number, deflate, no flags, no time,\n * and the Unix system code.\n */\nconst HEADER = Buffer.from([31, 139, 8, 0, 0, 0, 0, 0, 0, 3]);\n\n/** The gzip member of an empty body: the header, a final empty block, a CRC-32 of 0, and a size of 0. */\nconst EMPTY_MEMBER = Buffer.concat([HEADER, Buffer.from([3, 0, 0, 0, 0, 0, 0, 0, 0, 0])]);\n\n/**\n * The largest body that a pooled gzip stream compresses. Why a limit: above\n * about 64 KiB, the CRC-32 of a gzip body on the main thread costs more than\n * a new zlib stream does.\n */\nconst GZIP_POOLED_MAX_BYTES = 64 * 1024;\n\n/** The most zlib streams that wait for a body in each pool. Why a limit: an idle deflate stream keeps about 276 KiB of zlib state. */\nconst MAX_IDLE = 16;\n\nfunction ignore(): void {}\n\n/**\n * A zlib stream that compresses one body at a time, the target of its output\n * and of its failure, and the size of the longest body that it compressed.\n */\ntype Pooled = {\n\tstream: Transform;\n\toutput: (chunk: Buffer) => void;\n\tfail: (error: Error) => void;\n\tsize: number;\n};\n\n/** The idle zlib streams of one encoding, the last one given back last. */\ntype Pool = {\n\t/** A new zlib stream that finishes its output with each write. */\n\tcreate: () => Transform;\n\tidle: Pooled[];\n\t/**\n\t * Whether a reset keeps state of the earlier bodies, so a stream records\n\t * the size of its longest body (see {@link take}).\n\t */\n\tsized: boolean;\n\t/** Whether a reset lets the stream compress the next body. Else each body gets a new stream. */\n\treuses: boolean;\n};\n\nfunction newPooled(pool: Pool): Pooled {\n\tconst pooled: Pooled = { stream: pool.create(), output: ignore, fail: ignore, size: 0 };\n\tpooled.stream.on(\"data\", (chunk: Buffer) => {\n\t\tpooled.output(chunk);\n\t});\n\t// Why both: zlib destroys the stream at a failure, and then it never calls the write callback.\n\tpooled.stream.on(\"error\", (error) => {\n\t\tpooled.fail(error);\n\t});\n\tpooled.stream.on(\"close\", () => {\n\t\t// Why the check: a stream that the pool destroys has no body, and an error costs its stack.\n\t\tif (pooled.fail !== ignore) {\n\t\t\tpooled.fail(new Error(\"The zlib stream closed.\"));\n\t\t}\n\t});\n\treturn pooled;\n}\n\n/**\n * The deflate pool. Why `Z_FINISH`: when the output fills the buffer of the\n * stream exactly, the stream calls zlib again, and a sync flush then adds an\n * empty block. So the output would depend on earlier bodies.\n */\nconst DEFLATE_POOL: Pool = {\n\tcreate: () => createDeflateRaw({ flush: constants.Z_FINISH }),\n\tidle: [],\n\tsized: true,\n\treuses: true,\n};\n\n/**\n * The brotli quality of a response. Why 4: for HTML, its output is smaller\n * than gzip level 6, for the same CPU time. The `compression` middleware of\n * Express also uses 4.\n */\nconst BROTLI_QUALITY = 4;\n\n/**\n * The base-2 logarithm of the brotli window of a body up to\n * {@link BROTLI_HOLD_BYTES}, 256 KiB. Why not the default of 22 (4 MiB):\n * Node.js tells V8 the full size of each encoder's ring buffer as external\n * memory, and at 32 open encoders V8 then runs a full garbage collection for\n * every few responses.\n */\nconst BROTLI_WINDOW_BITS = 18;\n\n/**\n * The most bytes of a body that a brotli stream holds to pick the window: 256\n * KiB for a body that ends within them, else the default of 4 MiB. Why: a\n * stream has no length to pick from, and a repeat more than 256 KiB back costs\n * a page of 2.5 MB 30% more bytes.\n */\nconst BROTLI_HOLD_BYTES = 2 ** BROTLI_WINDOW_BITS;\n\nfunction brotliParams(windowBits: number): Record<number, number> {\n\treturn {\n\t\t[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,\n\t\t[constants.BROTLI_PARAM_QUALITY]: BROTLI_QUALITY,\n\t\t[constants.BROTLI_PARAM_LGWIN]: windowBits,\n\t};\n}\n\nconst BROTLI_PARAMS = brotliParams(BROTLI_WINDOW_BITS);\nconst BROTLI_LARGE_PARAMS = brotliParams(constants.BROTLI_DEFAULT_WINDOW);\n\n/**\n * The brotli pool. Why not sized: a reset makes a new brotli encoder with the\n * same parameters, so the output of a body never depends on an earlier one.\n */\nconst BROTLI_POOL: Pool = {\n\tcreate: () =>\n\t\tcreateBrotliCompress({ flush: constants.BROTLI_OPERATION_FINISH, params: BROTLI_PARAMS }),\n\tidle: [],\n\tsized: false,\n\t// Why not on Bun or Deno: after a reset, a Bun encoder forgets its quality, and a Deno encoder gives no bytes.\n\treuses: !(\"Bun\" in globalThis) && !(\"Deno\" in globalThis),\n};\n\n/**\n * An idle stream of `pool` for a body of `size` bytes, else a new one. It\n * takes a stream whose bodies were each no longer than this one: the longest\n * such, and of those the last one given back, whose memory is still in the\n * cache.\n *\n * Why for deflate: a reset keeps the window of zlib, and zlib reads the bytes\n * after the end of a body to hash and match its last bytes. After a longer\n * body, these are bytes of that body, so they could change the output of this\n * one. A stream whose bodies were no longer has only the zeros that zlib\n * writes after each body there, as a new stream does.\n */\nfunction take(pool: Pool, size: number): Pooled {\n\tconst { idle } = pool;\n\tlet best = -1;\n\tlet bestSize = -1;\n\tfor (let index = idle.length - 1; index >= 0; index -= 1) {\n\t\tconst each = idle[index]?.size ?? Infinity;\n\t\tif (each <= size && each > bestSize) {\n\t\t\tbest = index;\n\t\t\tbestSize = each;\n\t\t}\n\t}\n\tif (best === -1) {\n\t\treturn newPooled(pool);\n\t}\n\tconst taken = idle[best];\n\tconst last = idle.pop();\n\tif (taken == null || last == null) {\n\t\treturn newPooled(pool);\n\t}\n\t// Why move the last one into the gap: the order of the others does not matter, and it costs no copy.\n\tif (last !== taken) {\n\t\tidle[best] = last;\n\t}\n\treturn taken;\n}\n\n/**\n * Gives back a stream of `pool` after its body. Why reset: the next body must\n * not use the bytes of this one as a dictionary. When the pool is full, it\n * keeps the streams of the shortest bodies, which more bodies can take.\n */\nfunction release(pool: Pool, pooled: Pooled): void {\n\tpooled.output = ignore;\n\tpooled.fail = ignore;\n\tconst { stream } = pooled;\n\t// Why check the queues: a stream with output or input still queued would give it to the next body.\n\tif (\n\t\t!pool.reuses ||\n\t\tstream.destroyed ||\n\t\tstream.readableLength !== 0 ||\n\t\tstream.writableLength !== 0\n\t) {\n\t\tstream.destroy();\n\t\treturn;\n\t}\n\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- each pool creates a zlib stream, which has `reset`.\n\t(stream as Transform & { reset: () => void }).reset();\n\t// Why the check: a reset that fails destroys the stream.\n\tif (stream.destroyed) {\n\t\treturn;\n\t}\n\tconst { idle } = pool;\n\tif (idle.length < MAX_IDLE) {\n\t\tidle.push(pooled);\n\t\treturn;\n\t}\n\tlet longest = 0;\n\tfor (let index = 1; index < idle.length; index += 1) {\n\t\tif ((idle[index]?.size ?? 0) > (idle[longest]?.size ?? 0)) {\n\t\t\tlongest = index;\n\t\t}\n\t}\n\tconst evicted = idle[longest];\n\tif (evicted != null && evicted.size > pooled.size) {\n\t\tidle[longest] = pooled;\n\t\tevicted.stream.destroy();\n\t} else {\n\t\tstream.destroy();\n\t}\n}\n\n/** Writes `chunk` to `stream`. zlib gives all the output of the chunk before this resolves. */\nasync function write(stream: Transform, chunk: Uint8Array): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tstream.write(chunk, (error) => {\n\t\t\tif (error == null) {\n\t\t\t\tresolve();\n\t\t\t} else {\n\t\t\t\treject(error);\n\t\t\t}\n\t\t});\n\t});\n}\n\n/**\n * The output of a stream of `pool` for a body of one chunk, in one zlib call.\n * `use` gets the stream while zlib compresses, so a cancel can destroy it,\n * and gets `undefined` before the stream goes back to the pool. Why only a\n * body of one chunk: a deflate reset keeps the old window, and a second write\n * reads its bytes as history. The output of one write is the same as from a\n * new stream, so it does not depend on an earlier body.\n */\nasync function compressOnce(\n\tpool: Pool,\n\tvalue: Uint8Array,\n\tuse: (pooled: Pooled | undefined) => void,\n): Promise<Buffer[]> {\n\tconst pooled = take(pool, value.byteLength);\n\tuse(pooled);\n\tconst parts: Buffer[] = [];\n\tpooled.output = (chunk) => {\n\t\tparts.push(chunk);\n\t};\n\ttry {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tpooled.fail = reject;\n\t\t\tpooled.stream.write(value, (error) => {\n\t\t\t\tif (error != null) {\n\t\t\t\t\treject(error);\n\t\t\t\t} else if (pooled.stream.destroyed) {\n\t\t\t\t\treject(new Error(\"The zlib stream closed.\"));\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t} catch (error) {\n\t\tpooled.output = ignore;\n\t\tpooled.fail = ignore;\n\t\tpooled.stream.destroy();\n\t\tthrow error;\n\t}\n\tif (pool.sized) {\n\t\tpooled.size = Math.max(pooled.size, value.byteLength);\n\t}\n\t// Why first: a cancel after this must not destroy a stream that the pool gives to another body.\n\tuse(undefined);\n\trelease(pool, pooled);\n\treturn parts;\n}\n\n/**\n * The gzip member of a body of one chunk: the raw deflate output of a pooled\n * stream, with the header and the trailer written here.\n */\nasync function gzipOnce(\n\tvalue: Uint8Array,\n\tuse: (pooled: Pooled | undefined) => void,\n): Promise<Buffer> {\n\tconst parts = await compressOnce(DEFLATE_POOL, value, use);\n\tconst trailer = Buffer.allocUnsafe(8);\n\ttrailer.writeUInt32LE(crc32(value), 0);\n\ttrailer.writeUInt32LE(value.byteLength, 4);\n\treturn Buffer.concat([HEADER, ...parts, trailer]);\n}\n\n/** The brotli stream of a body of one chunk, from a pooled encoder. */\nasync function brotliOnce(\n\tvalue: Uint8Array,\n\tuse: (pooled: Pooled | undefined) => void,\n): Promise<Buffer> {\n\treturn Buffer.concat(await compressOnce(BROTLI_POOL, value, use));\n}\n\n/** How {@link zlibStream} compresses a body. */\ntype Codec = {\n\t/** A new zlib stream that flushes after each write. */\n\tcreate: () => Transform;\n\t/** The output for a body with no bytes. */\n\tempty: Buffer;\n\t/**\n\t * The output for a body of one chunk, up to `onceMaxBytes`, with no new\n\t * zlib stream. `use` gets the zlib stream while it compresses.\n\t */\n\tonce: (value: Uint8Array, use: (pooled: Pooled | undefined) => void) => Promise<Buffer>;\n\tonceMaxBytes: number;\n\t/**\n\t * A new zlib stream for a body longer than `onceMaxBytes`, which\n\t * {@link zlibStream} holds until it knows that. Without it, the stream\n\t * holds nothing, and each body gets `create`.\n\t */\n\tcreateLarge?: () => Transform;\n};\n\n/**\n * The start of a body that {@link zlibStream} held, whether the source ended\n * with it, and whether the body is longer than the hold.\n */\ntype Start = { value: Uint8Array; done: boolean; large: boolean };\n\n/**\n * The most chunks that {@link zlibStream} holds. Why: a source that gives each\n * chunk at once keeps the hold in one turn of the event loop, and 262,144\n * chunks of 1 byte blocked it for 215 ms on an Apple M3 Max.\n */\nconst HOLD_MAX_CHUNKS = 1024;\n\nfunction join(chunks: Uint8Array[], size: number): Uint8Array {\n\tconst [first] = chunks;\n\treturn chunks.length === 1 && first != null ? first : Buffer.concat(chunks, size);\n}\n\n/**\n * Compresses a byte stream with `codec`. Each written chunk is readable at\n * once. It reads the next source chunk only when the consumer pulls, so a\n * slow client holds back the source. When the source ends by the time zlib\n * finishes a chunk, that chunk and the end of the stream go out as one. Why:\n * the host writes each chunk to the socket on its own, and a write costs more\n * than its few bytes.\n *\n * With `codec.createLarge`, it first holds the body up to\n * `codec.onceMaxBytes`, the end, or a wait of the source, and then writes\n * what it holds.\n */\nfunction zlibStream(source: ReadableStream<Uint8Array>, codec: Codec): ReadableStream<Uint8Array> {\n\tconst reader = source.getReader();\n\tlet ended = false;\n\tconst markEnded = () => {\n\t\tended = true;\n\t};\n\t// Why a flag: after each zlib write, it tells with no read whether the source ended meanwhile.\n\tvoid reader.closed.then(markEnded, () => {});\n\t/** The zlib stream of a body of more than one chunk. */\n\tlet zlib: Transform | undefined;\n\t/** The pooled zlib stream while it compresses the one chunk of a body. */\n\tlet pooled: Pooled | undefined;\n\tlet started = false;\n\tlet canceled = false;\n\t/** The source read that is still open after a hold. */\n\tlet pending: Promise<ReadResult> | undefined;\n\t/** The next source chunk with bytes, or the end. */\n\tconst read = async () => {\n\t\tlet chunk = await (pending ?? reader.read());\n\t\tpending = undefined;\n\t\t// Why skip empty chunks: zlib writes nothing for one, and a pull that enqueues nothing is not\n\t\t// called again.\n\t\twhile (!chunk.done && chunk.value.byteLength === 0) {\n\t\t\tchunk = await reader.read();\n\t\t}\n\t\treturn chunk;\n\t};\n\t/**\n\t * `first` and the chunks after it, up to `max` bytes, until the source ends,\n\t * gives an empty chunk, or leaves a read open for a turn of the event loop.\n\t * Why stop on a wait: the source waits for data, such as a React\n\t * `<Suspense>` boundary, and what it gave must reach the client now.\n\t */\n\tconst hold = async (first: Uint8Array, max: number): Promise<Start> => {\n\t\tconst parts = [first];\n\t\tlet size = first.byteLength;\n\t\t/** Resolves at the end of this turn of the event loop. Why one for each turn: an immediate costs more than a read. */\n\t\tlet turn: Promise<undefined> | undefined;\n\t\tconst endOfTurn = async () =>\n\t\t\tnew Promise<undefined>((resolve) => {\n\t\t\t\tsetImmediate(() => {\n\t\t\t\t\tturn = undefined;\n\t\t\t\t\tresolve(undefined);\n\t\t\t\t});\n\t\t\t});\n\t\twhile (size <= max && parts.length < HOLD_MAX_CHUNKS) {\n\t\t\tpending ??= reader.read();\n\t\t\tturn ??= endOfTurn();\n\t\t\t// oxlint-disable-next-line no-await-in-loop -- each read waits for the source.\n\t\t\tconst result = await Promise.race([pending, turn]);\n\t\t\tif (result == null) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tpending = undefined;\n\t\t\tif (result.done) {\n\t\t\t\treturn { value: join(parts, size), done: true, large: false };\n\t\t\t}\n\t\t\t// Why stop on an empty chunk: a read that resolves at once never lets the turn end.\n\t\t\tif (result.value.byteLength === 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// Why give it to the next read: a join would copy the large chunk.\n\t\t\tif (size + result.value.byteLength > max) {\n\t\t\t\tpending = Promise.resolve(result);\n\t\t\t\treturn { value: join(parts, size), done: false, large: true };\n\t\t\t}\n\t\t\tparts.push(result.value);\n\t\t\tsize += result.value.byteLength;\n\t\t}\n\t\treturn { value: join(parts, size), done: false, large: size > max };\n\t};\n\t/** The zlib output that waits for the next enqueue. */\n\tlet held: Buffer[] = [];\n\tlet heldBytes = 0;\n\tconst enqueueHeld = (controller: ReadableStreamDefaultController<Uint8Array>) => {\n\t\tconst [first] = held;\n\t\tif (first == null) {\n\t\t\treturn;\n\t\t}\n\t\t// Why no copy for one chunk: zlib gives each chunk its own bytes, and it never writes them again.\n\t\tcontroller.enqueue(held.length === 1 ? first : Buffer.concat(held));\n\t\theld = [];\n\t\theldBytes = 0;\n\t};\n\tconst startZlib = (\n\t\tbody: ZlibBody,\n\t\tcontroller: ReadableStreamDefaultController<Uint8Array>,\n\t\tcreate: () => Transform,\n\t): Transform => {\n\t\tconst created = create();\n\t\tcreated.on(\"data\", (chunk: Buffer) => {\n\t\t\theld.push(chunk);\n\t\t\theldBytes += chunk.byteLength;\n\t\t\t// Why: the output of a large source chunk goes out while zlib still compresses the rest.\n\t\t\tif (heldBytes >= constants.Z_DEFAULT_CHUNK) {\n\t\t\t\tenqueueHeld(controller);\n\t\t\t}\n\t\t});\n\t\tcreated.on(\"end\", () => {\n\t\t\tbody.busy = false;\n\t\t\tenqueueHeld(controller);\n\t\t\tcontroller.close();\n\t\t});\n\t\tcreated.on(\"error\", (error) => {\n\t\t\tbody.busy = false;\n\t\t\tcontroller.error(error);\n\t\t});\n\t\treturn created;\n\t};\n\tconst stream: ZlibBody = new ZlibBody(\n\t\t{\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tconst chunk = await read();\n\t\t\t\t\tlet create = codec.create;\n\t\t\t\t\tlet start: Start | undefined;\n\t\t\t\t\tif (!started) {\n\t\t\t\t\t\tstarted = true;\n\t\t\t\t\t\tif (chunk.done) {\n\t\t\t\t\t\t\tcontroller.enqueue(codec.empty);\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstream.busy = true;\n\t\t\t\t\t\t// Why wait: a source that closes in the pull that gave this chunk ends one microtask later.\n\t\t\t\t\t\tawait Promise.resolve();\n\t\t\t\t\t\tconst { createLarge, onceMaxBytes } = codec;\n\t\t\t\t\t\tstart =\n\t\t\t\t\t\t\tended || createLarge == null\n\t\t\t\t\t\t\t\t? { value: chunk.value, done: ended, large: chunk.value.byteLength > onceMaxBytes }\n\t\t\t\t\t\t\t\t: await hold(chunk.value, onceMaxBytes);\n\t\t\t\t\t\t// Why: a cancel during the hold ran before this stream had an encoder to destroy.\n\t\t\t\t\t\tif (canceled) {\n\t\t\t\t\t\t\tstream.busy = false;\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (start.done && !start.large) {\n\t\t\t\t\t\t\tconst output = await codec.once(start.value, (each) => {\n\t\t\t\t\t\t\t\tpooled = each;\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.busy = false;\n\t\t\t\t\t\t\tcontroller.enqueue(output);\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (createLarge != null && start.large) {\n\t\t\t\t\t\t\tcreate = createLarge;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tzlib ??= startZlib(stream, controller, create);\n\t\t\t\t\tstream.busy = true;\n\t\t\t\t\tif (chunk.done) {\n\t\t\t\t\t\tzlib.end();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait write(zlib, start?.value ?? chunk.value);\n\t\t\t\t\tended ||= start?.done === true;\n\t\t\t\t\t// Why check `pending`: an open read can hold the last chunk when the source closes.\n\t\t\t\t\tif (ended && pending == null) {\n\t\t\t\t\t\tzlib.end();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tstream.busy = false;\n\t\t\t\t\t// Why the output is here: zlib emits the output of a chunk before it calls the write\n\t\t\t\t\t// callback, so this pull enqueues a chunk and the consumer's read does not wait.\n\t\t\t\t\tenqueueHeld(controller);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tstream.busy = false;\n\t\t\t\t\tzlib?.destroy();\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t\t// Why cancel the source: a client disconnect must reach the handler, so it stops its work.\n\t\t\tasync cancel(reason) {\n\t\t\t\tcanceled = true;\n\t\t\t\tzlib?.destroy();\n\t\t\t\t// Why destroy: a stream that a write still uses must never go back to the pool.\n\t\t\t\tpooled?.stream.destroy();\n\t\t\t\treturn reader.cancel(reason);\n\t\t\t},\n\t\t},\n\t\t// Why 0: the stream reads its source only when the consumer reads.\n\t\t{ highWaterMark: 0 },\n\t);\n\treturn stream;\n}\n\nconst GZIP: Codec = {\n\tcreate: () => createGzip({ flush: constants.Z_SYNC_FLUSH }),\n\tempty: EMPTY_MEMBER,\n\tonce: gzipOnce,\n\tonceMaxBytes: GZIP_POOLED_MAX_BYTES,\n};\n\n/**\n * Gzips a byte stream. `Z_SYNC_FLUSH` makes each written chunk readable at\n * once. It reads the next source chunk only when the consumer pulls, so a slow\n * client holds back the source. When the source ends by the time zlib\n * finishes a chunk, that chunk and the gzip trailer go out as one.\n *\n * A body that ends with its first chunk, up to 64 KiB, takes a pooled raw\n * deflate stream. Why: a new zlib stream costs more main-thread time than\n * zlib takes for a small page.\n *\n * @example\n * new Response(gzipStream(response.body), response);\n */\nexport function gzipStream(source: ReadableStream<Uint8Array>): ReadableStream<Uint8Array> {\n\treturn zlibStream(source, GZIP);\n}\n\nconst BROTLI: Codec = {\n\tcreate: () =>\n\t\tcreateBrotliCompress({ flush: constants.BROTLI_OPERATION_FLUSH, params: BROTLI_PARAMS }),\n\tempty: brotliCompressSync(new Uint8Array(), { params: BROTLI_PARAMS }),\n\tonce: brotliOnce,\n\tonceMaxBytes: BROTLI_HOLD_BYTES,\n\tcreateLarge: () =>\n\t\tcreateBrotliCompress({\n\t\t\tflush: constants.BROTLI_OPERATION_FLUSH,\n\t\t\tparams: BROTLI_LARGE_PARAMS,\n\t\t}),\n};\n\n/**\n * Compresses a byte stream with brotli, quality 4. `BROTLI_OPERATION_FLUSH`\n * makes each written chunk readable at once. It reads and ends as\n * {@link gzipStream} does.\n *\n * It holds the start of a body to pick the window, as\n * {@link BROTLI_HOLD_BYTES} says. When the source waits for its next chunk\n * first, the stream sends what it holds with the 256 KiB window.\n *\n * @example\n * new Response(brotliStream(response.body), response);\n */\nexport function brotliStream(source: ReadableStream<Uint8Array>): ReadableStream<U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