summaryrefslogtreecommitdiffhomepage
path: root/src/nodejs/unit-http/http_server.js
diff options
context:
space:
mode:
authorKonstantin Pavlov <thresh@nginx.com>2018-11-15 16:23:35 +0300
committerKonstantin Pavlov <thresh@nginx.com>2018-11-15 16:23:35 +0300
commit6ccba253f8d415337a09fb935606447791ce308c (patch)
treee0f9a8c5e8ede8cef1500c316d7534dd8de7b972 /src/nodejs/unit-http/http_server.js
parentbdde42999b36af85f2f04c0872fdd3e30af52027 (diff)
parenta4b02e17382ccbfc19410c644004c4615b2c2c29 (diff)
downloadunit-6ccba253f8d415337a09fb935606447791ce308c.tar.gz
unit-6ccba253f8d415337a09fb935606447791ce308c.tar.bz2
Merged with the default branch.1.6-1
Diffstat (limited to 'src/nodejs/unit-http/http_server.js')
-rwxr-xr-xsrc/nodejs/unit-http/http_server.js35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js
index fa7b8e9b..57163c0b 100755
--- a/src/nodejs/unit-http/http_server.js
+++ b/src/nodejs/unit-http/http_server.js
@@ -78,7 +78,7 @@ ServerResponse.prototype.setHeader = function setHeader(key, value) {
this.removeHeader(key);
- this.headers[key] = value + "";
+ this.headers[key] = value;
this.headers_len += header_len + (header_key_len * header_count);
this.headers_count += header_count;
};
@@ -227,12 +227,11 @@ ServerResponse.prototype._writeBody = function(chunk, encoding, callback) {
ServerResponse.prototype.write = function write(chunk, encoding, callback) {
this._writeBody(chunk, encoding, callback);
- return this;
+ return true;
};
ServerResponse.prototype.end = function end(chunk, encoding, callback) {
this._writeBody(chunk, encoding, callback);
- unit_lib.unit_response_end(this)
this.finished = true;
@@ -290,10 +289,10 @@ function Server(requestListener) {
EventEmitter.call(this);
this.unit = new unit_lib.Unit();
- this.unit.createServer();
-
this.unit.server = this;
+ this.unit.createServer();
+
this.socket = Socket;
this.request = ServerRequest;
this.response = ServerResponse;
@@ -318,10 +317,34 @@ Server.prototype.listen = function () {
this.unit.listen();
};
+Server.prototype.run_events = function (server, req, res) {
+ /* Important!!! setImmediate starts the next iteration in Node.js loop. */
+ setImmediate(function () {
+ server.emit("request", req, res);
+
+ Promise.resolve().then(() => {
+ let buf = server.unit._read(req.socket.req_pointer);
+
+ if (buf.length != 0) {
+ req.emit("data", buf);
+ }
+
+ req.emit("end");
+ });
+
+ Promise.resolve().then(() => {
+ req.emit("finish");
+
+ if (res.finished) {
+ unit_lib.unit_response_end(res);
+ }
+ });
+ });
+};
+
function connectionListener(socket) {
}
-
module.exports = {
STATUS_CODES: http.STATUS_CODES,
Server,