@tesser-sh/gateway 0.66.0 → 0.67.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +17 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -264,7 +264,7 @@ function gatewayHostBox(gatewayHost, hostname) {
264
264
 
265
265
  // ../protocol/src/mux.ts
266
266
  var MUX_WINDOW = 262144, MUX_CHUNK = 65536;
267
- var MUX_PING = "tesser:ping", MUX_PONG = "tesser:pong";
267
+ var WS_PING = "tesser:ping", WS_PONG = "tesser:pong";
268
268
  function closeCode(code) {
269
269
  if (code === 1005)
270
270
  return 1000;
@@ -512,19 +512,24 @@ var wakingPage = Effect2.fn("Proxy.wakingPage")(function* (request, box, port, s
512
512
  if (box.app === "none")
513
513
  return yield* page(request, { kind: "idle", box: viewerBox(box) });
514
514
  return yield* notAnswering(request, box, port);
515
- }), RECHECK = Duration.seconds(3), serve = Effect2.fn("Proxy.serve")(function* (request, route, box) {
515
+ }), RECHECK = Duration.seconds(3), REPLAY_LIMIT = 1048576, bodyRetry = { ...startingRetry, schedule: Schedule.spaced(Duration.millis(250)), times: 3 }, serve = Effect2.fn("Proxy.serve")(function* (request, route, box) {
516
516
  let { port, path, headers } = route;
517
517
  if (request.headers.get("upgrade")?.toLowerCase() === "websocket")
518
518
  return { _tag: "websocket", box, port, path, headers };
519
- let waker = yield* Waker, replayable = request.method === "GET" || request.method === "HEAD", document = wantsDocument(request), attempt = Effect2.suspend(() => route.fetch(box, new Request(`http://${headers.get("host")}${path}`, {
520
- method: request.method,
521
- headers,
522
- body: replayable ? void 0 : request.body,
523
- redirect: "manual",
524
- signal: request.signal,
525
- ...replayable ? {} : { duplex: "half" }
526
- }))), stillUp = (refusal) => waker.awake(box.boxId).pipe(Effect2.catchTag("DirectoryUnavailable", () => Effect2.fail(refusal))), retried = attempt.pipe(Effect2.tapErrorTag("UpstreamRefused", stillUp), Effect2.retry(startingRetry));
527
- return yield* (document || !replayable ? attempt : retried).pipe(Effect2.flatMap((response) => Effect2.map(route.present(box, response), respond)), Effect2.catchTags({
519
+ let waker = yield* Waker, sent = request.method === "GET" || request.method === "HEAD" ? null : request.body, replayable = sent === null || Number(request.headers.get("content-length") ?? 1 / 0) <= REPLAY_LIMIT, document = wantsDocument(request), buffered = sent === null || !replayable ? Effect2.succeed(sent) : Effect2.tryPromise({ try: () => request.arrayBuffer(), catch: () => new UpstreamRefused({ boxId: box.boxId, port }) }), stillUp = (refusal) => waker.awake(box.boxId).pipe(Effect2.catchTag("DirectoryUnavailable", () => Effect2.fail(refusal)));
520
+ return yield* buffered.pipe(Effect2.flatMap((body) => {
521
+ let attempt = Effect2.suspend(() => route.fetch(box, new Request(`http://${headers.get("host")}${path}`, {
522
+ method: request.method,
523
+ headers,
524
+ body,
525
+ redirect: "manual",
526
+ signal: request.signal,
527
+ ...replayable ? {} : { duplex: "half" }
528
+ })));
529
+ if (document || !replayable)
530
+ return attempt;
531
+ return attempt.pipe(Effect2.tapErrorTag("UpstreamRefused", stillUp), Effect2.retry(body === null ? startingRetry : bodyRetry));
532
+ }), Effect2.flatMap((response) => Effect2.map(route.present(box, response), respond)), Effect2.catchTags({
528
533
  UpstreamRefused: (refusal) => document ? stillUp(refusal).pipe(Effect2.timeoutOption(RECHECK), Effect2.flatMap((up) => up._tag === "Some" ? refused(request, box, port) : comingUp(request, box, port)), Effect2.catchTag("UpstreamRefused", () => refused(request, box, port))) : notAnswering(request, box, port),
529
534
  UpstreamTimedOut: () => notAnswering(request, box, port)
530
535
  }));
@@ -1063,7 +1068,7 @@ class BoxRelay extends DurableObject {
1063
1068
  lookups = /* @__PURE__ */ new Map;
1064
1069
  constructor(ctx, env) {
1065
1070
  super(ctx, env);
1066
- ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair(MUX_PING, MUX_PONG));
1071
+ ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair(WS_PING, WS_PONG));
1067
1072
  }
1068
1073
  boxSocket() {
1069
1074
  return this.ctx.getWebSockets("box").find((ws) => ws.deserializeAttachment()?.replaced !== !0) ?? null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tesser-sh/gateway",
3
- "version": "0.66.0",
3
+ "version": "0.67.1",
4
4
  "description": "Tesser's share gateway as a Cloudflare Worker and Durable Object, deployed in your own account",
5
5
  "license": "MIT",
6
6
  "type": "module",