ultimate-express 1.2.28 → 1.2.30
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/application.js +3 -0
- package/src/response.js +10 -7
- package/src/router.js +1 -0
package/package.json
CHANGED
package/src/application.js
CHANGED
package/src/response.js
CHANGED
|
@@ -69,13 +69,12 @@ module.exports = class Response extends Writable {
|
|
|
69
69
|
this._req = req;
|
|
70
70
|
this._res = res;
|
|
71
71
|
this.headersSent = false;
|
|
72
|
-
this.aborted = false;
|
|
73
72
|
this.app = app;
|
|
74
73
|
this.locals = {};
|
|
74
|
+
this.finished = false;
|
|
75
75
|
this.aborted = false;
|
|
76
76
|
this.statusCode = 200;
|
|
77
77
|
this.chunkedTransfer = true;
|
|
78
|
-
this.finished = false;
|
|
79
78
|
this.totalSize = 0;
|
|
80
79
|
this.headers = {
|
|
81
80
|
'connection': 'keep-alive',
|
|
@@ -96,7 +95,7 @@ module.exports = class Response extends Writable {
|
|
|
96
95
|
});
|
|
97
96
|
this.body = undefined;
|
|
98
97
|
this.on('error', (err) => {
|
|
99
|
-
if(this.
|
|
98
|
+
if(this.finished) {
|
|
100
99
|
return;
|
|
101
100
|
}
|
|
102
101
|
this._res.cork(() => {
|
|
@@ -121,6 +120,10 @@ module.exports = class Response extends Writable {
|
|
|
121
120
|
err.code = 'ECONNABORTED';
|
|
122
121
|
return this.destroy(err);
|
|
123
122
|
}
|
|
123
|
+
if(this.finished) {
|
|
124
|
+
const err = new Error('Response already finished');
|
|
125
|
+
return this.destroy(err);
|
|
126
|
+
}
|
|
124
127
|
this._res.cork(() => {
|
|
125
128
|
if(!this.headersSent) {
|
|
126
129
|
this.writeHead(this.statusCode);
|
|
@@ -149,7 +152,7 @@ module.exports = class Response extends Writable {
|
|
|
149
152
|
if(!ok) {
|
|
150
153
|
// wait until uWS is ready to accept more data
|
|
151
154
|
this._res.onWritable((offset) => {
|
|
152
|
-
if(this.
|
|
155
|
+
if(this.finished) {
|
|
153
156
|
return true;
|
|
154
157
|
}
|
|
155
158
|
const [ok, done] = this._res.tryEnd(chunk.slice(offset - lastOffset), this.totalSize);
|
|
@@ -462,7 +465,7 @@ module.exports = class Response extends Writable {
|
|
|
462
465
|
// serve smaller files using workers
|
|
463
466
|
if(this.app.workers.length && stat.size < 768 * 1024 && !ranged) {
|
|
464
467
|
this.app.readFileWithWorker(fullpath).then((data) => {
|
|
465
|
-
if(this._res.
|
|
468
|
+
if(this._res.finished) {
|
|
466
469
|
return;
|
|
467
470
|
}
|
|
468
471
|
this.end(data);
|
|
@@ -730,7 +733,7 @@ module.exports = class Response extends Writable {
|
|
|
730
733
|
|
|
731
734
|
function pipeStreamOverResponse(res, readStream, totalSize, callback) {
|
|
732
735
|
readStream.on('data', (chunk) => {
|
|
733
|
-
if(res.
|
|
736
|
+
if(res.finished) {
|
|
734
737
|
return readStream.destroy();
|
|
735
738
|
}
|
|
736
739
|
res._res.cork(() => {
|
|
@@ -756,7 +759,7 @@ function pipeStreamOverResponse(res, readStream, totalSize, callback) {
|
|
|
756
759
|
res._res.abOffset = lastOffset;
|
|
757
760
|
|
|
758
761
|
res._res.onWritable((offset) => {
|
|
759
|
-
if(res.
|
|
762
|
+
if(res.finished) {
|
|
760
763
|
return true;
|
|
761
764
|
}
|
|
762
765
|
const [ok, done] = res._res.tryEnd(res._res.ab.slice(offset - res._res.abOffset), totalSize);
|
package/src/router.js
CHANGED