@datatruck/cli 0.36.7 → 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.
@@ -689,6 +689,10 @@
689
689
  "keepAliveTimeout": {
690
690
  "type": "number"
691
691
  },
692
+ "contentLength": {
693
+ "default": true,
694
+ "type": "boolean"
695
+ },
692
696
  "allowlist": {
693
697
  "type": "object",
694
698
  "properties": {
@@ -15,6 +15,10 @@ export type DatatruckRepositoryServerOptions = {
15
15
  remoteAddressHeader: string;
16
16
  };
17
17
  keepAliveTimeout?: number;
18
+ /**
19
+ * @default true
20
+ */
21
+ contentLength?: boolean;
18
22
  allowlist?: {
19
23
  /**
20
24
  * @default true
@@ -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);
@@ -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.7",
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": {