@ndiinginc/router 4.16.1 → 4.16.2
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 +1 -1
- package/src/response.js +9 -15
package/package.json
CHANGED
package/src/response.js
CHANGED
|
@@ -16,10 +16,8 @@ class Response extends http.ServerResponse {
|
|
|
16
16
|
* @param {string} data
|
|
17
17
|
*/
|
|
18
18
|
send(data) {
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
"Content-Length": Buffer.byteLength(data),
|
|
22
|
-
});
|
|
19
|
+
this.setHeader("Content-Type", "text/html");
|
|
20
|
+
this.setHeader("Content-Length", Buffer.byteLength(data));
|
|
23
21
|
this.end(data);
|
|
24
22
|
}
|
|
25
23
|
|
|
@@ -28,10 +26,8 @@ class Response extends http.ServerResponse {
|
|
|
28
26
|
*/
|
|
29
27
|
json(data) {
|
|
30
28
|
const body = JSON.stringify(data);
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
"Content-Length": Buffer.byteLength(body),
|
|
34
|
-
});
|
|
29
|
+
this.setHeader("Content-Type", "application/json");
|
|
30
|
+
this.setHeader("Content-Length", Buffer.byteLength(body));
|
|
35
31
|
this.end(body);
|
|
36
32
|
}
|
|
37
33
|
|
|
@@ -41,23 +37,21 @@ class Response extends http.ServerResponse {
|
|
|
41
37
|
*/
|
|
42
38
|
download(filePath, filename) {
|
|
43
39
|
if (!fs.existsSync(filePath)) {
|
|
44
|
-
this.
|
|
40
|
+
this.status(404);
|
|
45
41
|
return this.end();
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
const stat = fs.statSync(filePath);
|
|
49
45
|
const basename = filename || path.basename(filePath);
|
|
50
46
|
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"Content-Disposition": `attachment; filename="${basename}"`,
|
|
55
|
-
});
|
|
47
|
+
this.setHeader("Content-Type", "application/octet-stream");
|
|
48
|
+
this.setHeader("Content-Length", stat.size);
|
|
49
|
+
this.setHeader("Content-Disposition", `attachment; filename="${basename}"`);
|
|
56
50
|
|
|
57
51
|
const stream = fs.createReadStream(filePath);
|
|
58
52
|
stream.on("error", (err) => {
|
|
59
53
|
if (!this.headersSent) {
|
|
60
|
-
this.
|
|
54
|
+
this.status(500);
|
|
61
55
|
}
|
|
62
56
|
this.end();
|
|
63
57
|
});
|