summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlexander Borisov <alexander.borisov@nginx.com>2018-12-19 15:55:54 +0300
committerAlexander Borisov <alexander.borisov@nginx.com>2018-12-19 15:55:54 +0300
commitde3c062c6e3e869d726b93a1ffe617059df7611a (patch)
tree2c2cba0e96befd1dffe7df0b1b565f87e414d7d8
parentaeb026c8ab41b907f2e19a9f2fa978717d034830 (diff)
downloadunit-de3c062c6e3e869d726b93a1ffe617059df7611a.tar.gz
unit-de3c062c6e3e869d726b93a1ffe617059df7611a.tar.bz2
Node.js: buffering HTTP headers before writing the body.
-rwxr-xr-xsrc/nodejs/unit-http/http_server.js23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js
index 57163c0b..47851c98 100755
--- a/src/nodejs/unit-http/http_server.js
+++ b/src/nodejs/unit-http/http_server.js
@@ -178,21 +178,16 @@ function writeHead(statusCode, reason, obj) {
}
}
}
-
- unit_lib.unit_response_headers(this, statusCode, this.headers, this.headers_count, this.headers_len);
-
- this.headersSent = true;
};
ServerResponse.prototype._writeBody = function(chunk, encoding, callback) {
var contentLength = 0;
if (!this.headersSent) {
- this.writeHead(this.statusCode);
- }
+ unit_lib.unit_response_headers(this, this.statusCode, this.headers,
+ this.headers_count, this.headers_len);
- if (this.finished) {
- return this;
+ this.headersSent = true;
}
if (typeof chunk === 'function') {
@@ -225,15 +220,23 @@ ServerResponse.prototype._writeBody = function(chunk, encoding, callback) {
};
ServerResponse.prototype.write = function write(chunk, encoding, callback) {
+ if (this.finished) {
+ throw new Error("Write after end");
+ }
+
this._writeBody(chunk, encoding, callback);
return true;
};
ServerResponse.prototype.end = function end(chunk, encoding, callback) {
- this._writeBody(chunk, encoding, callback);
+ if (!this.finished) {
+ this._writeBody(chunk, encoding, callback);
- this.finished = true;
+ unit_lib.unit_response_end(this);
+
+ this.finished = true;
+ }
return this;
};