@faapi/faapi 4.0.0 → 4.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.
package/dist/index.js CHANGED
@@ -4725,7 +4725,7 @@ function attachWebSocket(options) {
4725
4725
  // src/server/createServer.ts
4726
4726
  init_generateSchemaFiles();
4727
4727
  var DEFAULT_BODY_LIMIT = 10 * 1024 * 1024;
4728
- function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
4728
+ function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT, requestSignal) {
4729
4729
  const forwardedProto = req.headers["x-forwarded-proto"];
4730
4730
  const protocol = Array.isArray(forwardedProto) ? forwardedProto[0]?.split(",")[0]?.trim() ?? "http" : forwardedProto?.split(",")[0]?.trim() ?? "http";
4731
4731
  const host = req.headers.host ?? "localhost";
@@ -4733,7 +4733,10 @@ function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
4733
4733
  const headers = nodeHttpToWebHeaders(req);
4734
4734
  const method = req.method ?? "GET";
4735
4735
  if (method === "GET" || method === "HEAD") {
4736
- return { request: new Request(url.toString(), { method, headers }), url };
4736
+ return {
4737
+ request: new Request(url.toString(), { method, headers, signal: requestSignal }),
4738
+ url
4739
+ };
4737
4740
  }
4738
4741
  const contentLength = req.headers["content-length"];
4739
4742
  if (contentLength !== void 0) {
@@ -4749,7 +4752,8 @@ function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT) {
4749
4752
  method,
4750
4753
  headers,
4751
4754
  body: limitedStream,
4752
- duplex: "half"
4755
+ duplex: "half",
4756
+ signal: requestSignal
4753
4757
  }),
4754
4758
  url
4755
4759
  };
@@ -4888,8 +4892,8 @@ function createServer(options) {
4888
4892
  });
4889
4893
  return { server, routesRef };
4890
4894
  }
4891
- function prepareRequest(req, config, bodyLimit, trustedProxy, registries) {
4892
- const { request, url } = toWebRequest(req, bodyLimit);
4895
+ function prepareRequest(req, config, bodyLimit, trustedProxy, registries, requestSignal) {
4896
+ const { request, url } = toWebRequest(req, bodyLimit, requestSignal);
4893
4897
  const method = request.method.toUpperCase();
4894
4898
  const urlPath = url.pathname;
4895
4899
  const ctx = createContextFromUrl(
@@ -4975,8 +4979,19 @@ async function sendErrorResponse(err, meta, res, onError, ctx) {
4975
4979
  async function handleRequest(routes, rootDir, dist, req, res, outerMiddlewares, onError, config, globalInjectors, bodyLimit, trustedProxy, registries) {
4976
4980
  let meta = { headers: {}, setCookies: [] };
4977
4981
  let ctx;
4982
+ const abortController = new AbortController();
4983
+ res.on("close", () => {
4984
+ if (!res.writableEnded) abortController.abort();
4985
+ });
4978
4986
  try {
4979
- const prepared = prepareRequest(req, config, bodyLimit, trustedProxy, registries);
4987
+ const prepared = prepareRequest(
4988
+ req,
4989
+ config,
4990
+ bodyLimit,
4991
+ trustedProxy,
4992
+ registries,
4993
+ abortController.signal
4994
+ );
4980
4995
  ctx = prepared.ctx;
4981
4996
  meta = prepared.meta;
4982
4997
  const { request, url, method, urlPath } = prepared;