vite-plugin-rpx 0.11.37 → 0.11.39

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -9
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -23267,7 +23267,7 @@ async function proxyViaPool(reqOpts) {
23267
23267
  const written = conn.socket.write(payload);
23268
23268
  if (written < payload.length)
23269
23269
  await conn.writeAll(payload.subarray(written));
23270
- return await readResponse(pool, conn, isHead);
23270
+ return await readResponse(pool, conn, isHead, reqOpts.signal);
23271
23271
  } catch (err) {
23272
23272
  const retryable = err === STALE && attempt < MAX_STALE_RETRIES && (conn.fresh || isIdempotent(method));
23273
23273
  pool.destroy(conn);
@@ -23296,7 +23296,7 @@ async function waitForHead(conn) {
23296
23296
  }
23297
23297
  return headerEnd;
23298
23298
  }
23299
- async function readResponse(pool, conn, isHead) {
23299
+ async function readResponse(pool, conn, isHead, signal) {
23300
23300
  let head;
23301
23301
  for (;; ) {
23302
23302
  const headerEnd = await waitForHead(conn);
@@ -23316,7 +23316,10 @@ async function readResponse(pool, conn, isHead) {
23316
23316
  return new Response(null, { status: head.status, headers: responseHeaders });
23317
23317
  }
23318
23318
  if (head.chunked)
23319
- return new Response(chunkedStream(pool, conn, head.closeConn), { status: head.status, headers: responseHeaders });
23319
+ return new Response(chunkedStream(pool, conn, head.closeConn, signal), {
23320
+ status: head.status,
23321
+ headers: responseHeaders
23322
+ });
23320
23323
  if (head.contentLength >= 0) {
23321
23324
  const available = conn.len - conn.pos;
23322
23325
  if (available >= head.contentLength) {
@@ -23430,12 +23433,23 @@ function untilCloseStream(conn) {
23430
23433
  }
23431
23434
  });
23432
23435
  }
23433
- function chunkedStream(pool, conn, closeConn) {
23436
+ function chunkedStream(pool, conn, closeConn, signal) {
23434
23437
  conn.streamingBody = true;
23435
23438
  let remaining = 0;
23436
23439
  let needTrailerCrlf = false;
23437
23440
  let cancelled = false;
23438
- async function readLine() {
23441
+ let downstreamController;
23442
+ const cleanupSignal = () => signal?.removeEventListener("abort", abortDownstream);
23443
+ const abortDownstream = () => {
23444
+ if (cancelled)
23445
+ return;
23446
+ cancelled = true;
23447
+ pool.destroy(conn);
23448
+ try {
23449
+ downstreamController?.close();
23450
+ } catch {}
23451
+ };
23452
+ async function readLine(allowCleanEof = false) {
23439
23453
  for (;; ) {
23440
23454
  for (let i2 = conn.pos;i2 + 1 < conn.len; i2++) {
23441
23455
  if (conn.buf[i2] === 13 && conn.buf[i2 + 1] === 10) {
@@ -23444,14 +23458,24 @@ function chunkedStream(pool, conn, closeConn) {
23444
23458
  return line;
23445
23459
  }
23446
23460
  }
23447
- if (conn.closed)
23461
+ if (conn.closed) {
23462
+ if (allowCleanEof && conn.pos === conn.len)
23463
+ return null;
23448
23464
  throw new Error("upstream closed mid-chunk-header");
23465
+ }
23449
23466
  if (conn.len - conn.pos > MAX_HEADER_BYTES)
23450
23467
  throw new Error("upstream chunk header too large");
23451
23468
  await conn.waitForData(conn.len);
23452
23469
  }
23453
23470
  }
23454
23471
  return new ReadableStream({
23472
+ start(controller) {
23473
+ downstreamController = controller;
23474
+ if (signal?.aborted)
23475
+ abortDownstream();
23476
+ else
23477
+ signal?.addEventListener("abort", abortDownstream, { once: true });
23478
+ },
23455
23479
  async pull(controller) {
23456
23480
  try {
23457
23481
  for (;; ) {
@@ -23478,7 +23502,13 @@ function chunkedStream(pool, conn, closeConn) {
23478
23502
  await readLine();
23479
23503
  needTrailerCrlf = false;
23480
23504
  }
23481
- const sizeLine = await readLine();
23505
+ const sizeLine = await readLine(true);
23506
+ if (sizeLine === null) {
23507
+ pool.destroy(conn);
23508
+ cleanupSignal();
23509
+ controller.close();
23510
+ return;
23511
+ }
23482
23512
  const semi = sizeLine.indexOf(";");
23483
23513
  const size = Number.parseInt(semi === -1 ? sizeLine : sizeLine.slice(0, semi), 16);
23484
23514
  if (!Number.isInteger(size) || size < 0) {
@@ -23493,6 +23523,7 @@ function chunkedStream(pool, conn, closeConn) {
23493
23523
  break;
23494
23524
  }
23495
23525
  finishConn(pool, conn, closeConn);
23526
+ cleanupSignal();
23496
23527
  controller.close();
23497
23528
  return;
23498
23529
  }
@@ -23500,12 +23531,14 @@ function chunkedStream(pool, conn, closeConn) {
23500
23531
  }
23501
23532
  } catch (error) {
23502
23533
  pool.destroy(conn);
23534
+ cleanupSignal();
23503
23535
  if (!cancelled)
23504
23536
  controller.error(error);
23505
23537
  }
23506
23538
  },
23507
23539
  cancel() {
23508
23540
  cancelled = true;
23541
+ cleanupSignal();
23509
23542
  pool.destroy(conn);
23510
23543
  }
23511
23544
  });
@@ -23860,7 +23893,8 @@ function createProxyFetchHandler(getRoute, verbose, onNoRoute) {
23860
23893
  reqHeaders: req.headers,
23861
23894
  forwardedHost: hostname,
23862
23895
  originOverride,
23863
- body: req.body
23896
+ body: req.body,
23897
+ signal: req.signal
23864
23898
  });
23865
23899
  if (pool)
23866
23900
  markSuccess(pool, upstream);
@@ -26165,7 +26199,7 @@ init_utils();
26165
26199
  var package_default = {
26166
26200
  name: "@stacksjs/rpx",
26167
26201
  type: "module",
26168
- version: "0.11.37",
26202
+ version: "0.11.39",
26169
26203
  description: "A modern and smart reverse proxy.",
26170
26204
  author: "Chris Breuer <chris@stacksjs.org>",
26171
26205
  license: "MIT",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-rpx",
3
3
  "type": "module",
4
- "version": "0.11.37",
4
+ "version": "0.11.39",
5
5
  "description": "A modern and smart reverse proxy. Vite plugin.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -47,7 +47,7 @@
47
47
  "typecheck": "bunx tsc --noEmit"
48
48
  },
49
49
  "dependencies": {
50
- "@stacksjs/rpx": "0.11.37",
50
+ "@stacksjs/rpx": "0.11.39",
51
51
  "@stacksjs/tlsx": "^0.13.13"
52
52
  },
53
53
  "simple-git-hooks": {