@trops/dash-core 0.1.478 → 0.1.480

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.
@@ -47927,6 +47927,17 @@ var requestPrototype = {
47927
47927
  }
47928
47928
  });
47929
47929
  });
47930
+ Object.defineProperty(requestPrototype, Symbol.for("nodejs.util.inspect.custom"), {
47931
+ value: function(depth, options, inspectFn) {
47932
+ const props = {
47933
+ method: this.method,
47934
+ url: this.url,
47935
+ headers: this.headers,
47936
+ nativeRequest: this[requestCache]
47937
+ };
47938
+ return `Request (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
47939
+ }
47940
+ });
47930
47941
  Object.setPrototypeOf(requestPrototype, Request.prototype);
47931
47942
  var newRequest = (incoming, defaultHostname) => {
47932
47943
  const req = Object.create(requestPrototype);
@@ -48032,6 +48043,17 @@ var Response2 = class _Response {
48032
48043
  }
48033
48044
  });
48034
48045
  });
48046
+ Object.defineProperty(Response2.prototype, Symbol.for("nodejs.util.inspect.custom"), {
48047
+ value: function(depth, options, inspectFn) {
48048
+ const props = {
48049
+ status: this.status,
48050
+ headers: this.headers,
48051
+ ok: this.ok,
48052
+ nativeResponse: this[responseCache$1]
48053
+ };
48054
+ return `Response (lightweight) ${inspectFn(props, { ...options, depth: depth == null ? null : depth - 1 })}`;
48055
+ }
48056
+ });
48035
48057
  Object.setPrototypeOf(Response2, GlobalResponse);
48036
48058
  Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
48037
48059
 
@@ -48112,6 +48134,50 @@ if (typeof commonjsGlobal.crypto === "undefined") {
48112
48134
 
48113
48135
  // src/listener.ts
48114
48136
  var outgoingEnded = Symbol("outgoingEnded");
48137
+ var incomingDraining = Symbol("incomingDraining");
48138
+ var DRAIN_TIMEOUT_MS = 500;
48139
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
48140
+ var drainIncoming = (incoming) => {
48141
+ const incomingWithDrainState = incoming;
48142
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
48143
+ return;
48144
+ }
48145
+ incomingWithDrainState[incomingDraining] = true;
48146
+ if (incoming instanceof import_node_http22.Http2ServerRequest) {
48147
+ try {
48148
+ ;
48149
+ incoming.stream?.close?.(import_node_http22.constants.NGHTTP2_NO_ERROR);
48150
+ } catch {
48151
+ }
48152
+ return;
48153
+ }
48154
+ let bytesRead = 0;
48155
+ const cleanup = () => {
48156
+ clearTimeout(timer);
48157
+ incoming.off("data", onData);
48158
+ incoming.off("end", cleanup);
48159
+ incoming.off("error", cleanup);
48160
+ };
48161
+ const forceClose = () => {
48162
+ cleanup();
48163
+ const socket = incoming.socket;
48164
+ if (socket && !socket.destroyed) {
48165
+ socket.destroySoon();
48166
+ }
48167
+ };
48168
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
48169
+ timer.unref?.();
48170
+ const onData = (chunk) => {
48171
+ bytesRead += chunk.length;
48172
+ if (bytesRead > MAX_DRAIN_BYTES) {
48173
+ forceClose();
48174
+ }
48175
+ };
48176
+ incoming.on("data", onData);
48177
+ incoming.on("end", cleanup);
48178
+ incoming.on("error", cleanup);
48179
+ incoming.resume();
48180
+ };
48115
48181
  var handleRequestError = () => new Response(null, {
48116
48182
  status: 400
48117
48183
  });
@@ -48279,14 +48345,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
48279
48345
  setTimeout(() => {
48280
48346
  if (!incomingEnded) {
48281
48347
  setTimeout(() => {
48282
- incoming.destroy();
48283
- outgoing.destroy();
48348
+ drainIncoming(incoming);
48284
48349
  });
48285
48350
  }
48286
48351
  });
48287
48352
  }
48288
48353
  };
48289
48354
  }
48355
+ outgoing.on("finish", () => {
48356
+ if (!incomingEnded) {
48357
+ drainIncoming(incoming);
48358
+ }
48359
+ });
48290
48360
  }
48291
48361
  outgoing.on("close", () => {
48292
48362
  const abortController = req[abortControllerKey];
@@ -48301,7 +48371,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
48301
48371
  setTimeout(() => {
48302
48372
  if (!incomingEnded) {
48303
48373
  setTimeout(() => {
48304
- incoming.destroy();
48374
+ drainIncoming(incoming);
48305
48375
  });
48306
48376
  }
48307
48377
  });