@vbarbarosh/node-helpers 3.54.0 → 3.54.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.
- package/package.json +2 -1
- package/src/http_stream_range.js +5 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@vbarbarosh/node-helpers",
|
|
5
|
-
"version": "3.54.
|
|
5
|
+
"version": "3.54.1",
|
|
6
6
|
"description": "A set of helpers for JavaScript/Node.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"src"
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"form-data": "^4.0.0",
|
|
29
29
|
"htmlparser2": "^9.1.0",
|
|
30
30
|
"json-stable-stringify": "^1.0.2",
|
|
31
|
+
"mime-types": "^2.1.35",
|
|
31
32
|
"sanitize-filename": "^1.6.3",
|
|
32
33
|
"split": "^1.0.1",
|
|
33
34
|
"ssh2": "^1.15.0"
|
package/src/http_stream_range.js
CHANGED
|
@@ -5,6 +5,7 @@ const fs_fread = require('./fs_fread');
|
|
|
5
5
|
const fs_path_basename = require('./fs_path_basename');
|
|
6
6
|
const fs_size = require('./fs_size');
|
|
7
7
|
const http_range_parse = require('./http_range_parse');
|
|
8
|
+
const mime_types = require('mime-types');
|
|
8
9
|
|
|
9
10
|
// https://stackoverflow.com/questions/63649387/get-vs-head-methods-in-express-example#comment120040338_63649698
|
|
10
11
|
// > Note: the app.get() function is automatically called for the HTTP HEAD
|
|
@@ -23,8 +24,10 @@ async function http_stream_range(req, res, file)
|
|
|
23
24
|
// req.log(`[http_stream_range_begin] ${JSON.stringify(req.headers)}`);
|
|
24
25
|
|
|
25
26
|
const total = await fs_size(file);
|
|
27
|
+
const mime = mime_types.lookup(file);
|
|
26
28
|
|
|
27
29
|
if (req.method === 'HEAD') {
|
|
30
|
+
res.header('Content-Type', mime);
|
|
28
31
|
res.header('Content-Length', total);
|
|
29
32
|
res.header('Content-Disposition', `inline; filename=${escape_content_disposition(fs_path_basename(file))};`);
|
|
30
33
|
res.status(200);
|
|
@@ -55,12 +58,14 @@ async function http_stream_range(req, res, file)
|
|
|
55
58
|
// req.log(`[http_stream_range_range] ${JSON.stringify({range: req.headers.range, first, last, total, orig: req.headers.range})}`);
|
|
56
59
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
|
|
57
60
|
res.status(206);
|
|
61
|
+
res.header('Content-Type', mime);
|
|
58
62
|
res.header('Content-Range', `bytes ${first}-${last}/${total}`);
|
|
59
63
|
res.header('Content-Length', last - first + 1);
|
|
60
64
|
}
|
|
61
65
|
else {
|
|
62
66
|
first = 0;
|
|
63
67
|
last = total - 1;
|
|
68
|
+
res.header('Content-Type', mime);
|
|
64
69
|
res.header('Content-Length', last - first + 1);
|
|
65
70
|
}
|
|
66
71
|
|