ultimate-express 1.1.6 → 1.1.7
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 +8 -8
package/package.json
CHANGED
package/src/response.js
CHANGED
|
@@ -64,6 +64,8 @@ module.exports = class Response extends Writable {
|
|
|
64
64
|
this.locals = {};
|
|
65
65
|
this.aborted = false;
|
|
66
66
|
this.statusCode = 200;
|
|
67
|
+
this.chunkedTransfer = true;
|
|
68
|
+
this.totalSize = 0;
|
|
67
69
|
this.headers = {
|
|
68
70
|
'keep-alive': 'timeout=10'
|
|
69
71
|
};
|
|
@@ -98,8 +100,6 @@ module.exports = class Response extends Writable {
|
|
|
98
100
|
err.code = 'ECONNABORTED';
|
|
99
101
|
return this.destroy(err);
|
|
100
102
|
}
|
|
101
|
-
const isString = typeof chunk === 'string';
|
|
102
|
-
let isChunkedTransfer = true, totalSize;
|
|
103
103
|
this._res.cork(() => {
|
|
104
104
|
if(!this.headersSent) {
|
|
105
105
|
this.writeHead(this.statusCode);
|
|
@@ -107,14 +107,14 @@ module.exports = class Response extends Writable {
|
|
|
107
107
|
for(const header in this.headers) {
|
|
108
108
|
if(header === 'content-length') {
|
|
109
109
|
// if content-length is set, disable chunked transfer encoding, since size is known
|
|
110
|
-
|
|
111
|
-
totalSize = parseInt(this.headers[header]);
|
|
110
|
+
this.chunkedTransfer = false;
|
|
111
|
+
this.totalSize = parseInt(this.headers[header]);
|
|
112
112
|
continue;
|
|
113
113
|
}
|
|
114
114
|
this._res.writeHeader(header, this.headers[header]);
|
|
115
115
|
}
|
|
116
116
|
if(!this.headers['content-type']) {
|
|
117
|
-
this._res.writeHeader('content-type', 'text/html' + (
|
|
117
|
+
this._res.writeHeader('content-type', 'text/html' + (typeof chunk === 'string' ? `; charset=utf-8` : ''));
|
|
118
118
|
}
|
|
119
119
|
this.headersSent = true;
|
|
120
120
|
}
|
|
@@ -122,14 +122,14 @@ module.exports = class Response extends Writable {
|
|
|
122
122
|
chunk = Buffer.from(chunk);
|
|
123
123
|
chunk = chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength);
|
|
124
124
|
}
|
|
125
|
-
if(
|
|
125
|
+
if(this.chunkedTransfer) {
|
|
126
126
|
// chunked transfer encoding
|
|
127
127
|
this._res.write(chunk);
|
|
128
128
|
callback();
|
|
129
129
|
} else {
|
|
130
130
|
// fixed size transfer encoding
|
|
131
131
|
const lastOffset = this._res.getWriteOffset();
|
|
132
|
-
const [ok, done] = this._res.tryEnd(chunk, totalSize);
|
|
132
|
+
const [ok, done] = this._res.tryEnd(chunk, this.totalSize);
|
|
133
133
|
if(done) {
|
|
134
134
|
this.destroy();
|
|
135
135
|
this.socket.emit('close');
|
|
@@ -139,7 +139,7 @@ module.exports = class Response extends Writable {
|
|
|
139
139
|
if(!ok) {
|
|
140
140
|
// wait until uWS is ready to accept more data
|
|
141
141
|
this._res.onWritable((offset) => {
|
|
142
|
-
const [ok, done] = this._res.tryEnd(chunk.slice(offset - lastOffset), totalSize);
|
|
142
|
+
const [ok, done] = this._res.tryEnd(chunk.slice(offset - lastOffset), this.totalSize);
|
|
143
143
|
if(done) {
|
|
144
144
|
this.destroy();
|
|
145
145
|
this.socket.emit('close');
|