@datatruck/cli 0.36.6 → 0.36.8

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.
@@ -686,6 +686,13 @@
686
686
  }
687
687
  ]
688
688
  },
689
+ "keepAliveTimeout": {
690
+ "type": "number"
691
+ },
692
+ "contentLength": {
693
+ "default": true,
694
+ "type": "boolean"
695
+ },
689
696
  "allowlist": {
690
697
  "type": "object",
691
698
  "properties": {
@@ -14,6 +14,11 @@ export type DatatruckRepositoryServerOptions = {
14
14
  trustProxy?: true | {
15
15
  remoteAddressHeader: string;
16
16
  };
17
+ keepAliveTimeout?: number;
18
+ /**
19
+ * @default true
20
+ */
21
+ contentLength?: boolean;
17
22
  allowlist?: {
18
23
  /**
19
24
  * @default true
@@ -58,7 +58,7 @@ const getRemoteAddress = (req, options) => {
58
58
  };
59
59
  function createDatatruckRepositoryServer(inOptions, config = {}) {
60
60
  const counter = new math_1.Counter();
61
- return (0, http_2.createServer)(async (req, res) => {
61
+ const server = (0, http_2.createServer)(async (req, res) => {
62
62
  const url = req.url || "";
63
63
  if (url === "/" || url === "/favicon.ico")
64
64
  return res.end();
@@ -67,6 +67,7 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
67
67
  let responseError;
68
68
  req.on("error", (error) => (requestError = error));
69
69
  res.on("error", (error) => (responseError = error));
70
+ res.setHeader("X-Accel-Buffering", "no");
70
71
  try {
71
72
  const { repository, action, params } = parseUrl(url);
72
73
  if (!repository || !action)
@@ -93,7 +94,9 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
93
94
  else if (action === "download") {
94
95
  const [target] = params;
95
96
  const path = fs.resolvePath(target);
96
- await (0, http_1.sendFile)(req, res, path);
97
+ await (0, http_1.sendFile)(req, res, path, {
98
+ contentLength: options.contentLength ?? true,
99
+ });
97
100
  }
98
101
  else if (action === "writeFile") {
99
102
  const data = await (0, http_1.readRequestData)(req);
@@ -132,5 +135,8 @@ function createDatatruckRepositoryServer(inOptions, config = {}) {
132
135
  res.end();
133
136
  }
134
137
  });
138
+ if (typeof inOptions.keepAliveTimeout === "number")
139
+ server.keepAliveTimeout = inOptions.keepAliveTimeout;
140
+ return server;
135
141
  }
136
142
  exports.createDatatruckRepositoryServer = createDatatruckRepositoryServer;
@@ -10,6 +10,7 @@ export declare function fetchJson<T = any>(url: string, options?: RequestInit):
10
10
  export declare function post(url: string, data: string, options?: Omit<RequestInit, "method" | "body">): Promise<Response>;
11
11
  export declare function parseContentLength(value: string | undefined): number;
12
12
  export declare function sendFile(req: IncomingMessage, res: ServerResponse, path: string, options?: {
13
+ contentLength?: boolean;
13
14
  end?: boolean;
14
15
  checksum?: boolean;
15
16
  }): Promise<void>;
package/lib/utils/http.js CHANGED
@@ -62,7 +62,7 @@ async function sendFile(req, res, path, options = {}) {
62
62
  try {
63
63
  file = (0, fs_1.createReadStream)(path);
64
64
  const fileStat = await (0, promises_1.stat)(path);
65
- res.setHeader("Content-Length", fileStat.size);
65
+ res.setHeader(options.contentLength ?? true ? "Content-Length" : "x-content-length", fileStat.size);
66
66
  if (options.checksum)
67
67
  res.setHeader("x-checksum", await (0, crypto_1.calcFileHash)(path, "sha1"));
68
68
  file.pipe(res);
@@ -111,7 +111,9 @@ async function downloadFile(url, output, options = {}) {
111
111
  ...fetchOptions,
112
112
  signal: AbortSignal.timeout(timeout ?? 3600 * 1000), // 60m
113
113
  });
114
- length.total = parseContentLength(res.headers.get("content-length") ?? undefined);
114
+ length.total = parseContentLength(res.headers.get("content-length") ??
115
+ res.headers.get("x-content-length") ??
116
+ undefined);
115
117
  checksum = res.headers.get("x-checksum") ?? undefined;
116
118
  const body = stream_1.Readable.fromWeb(res.body);
117
119
  const progress = onProgress &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datatruck/cli",
3
- "version": "0.36.6",
3
+ "version": "0.36.8",
4
4
  "description": "Tool for creating and managing backups",
5
5
  "homepage": "https://github.com/swordev/datatruck#readme",
6
6
  "bugs": {