summaryrefslogtreecommitdiffhomepage
path: root/src/nodejs/unit-http/http_server.js
diff options
context:
space:
mode:
authorAlexander Borisov <alexander.borisov@nginx.com>2018-10-31 15:51:51 +0300
committerAlexander Borisov <alexander.borisov@nginx.com>2018-10-31 15:51:51 +0300
commitc838c3bd1580735e8020687f94e6307f13aba156 (patch)
treed88247c68c70ec4770d76037bd5fefcb836754ac /src/nodejs/unit-http/http_server.js
parent3b0afb16814353a5d34a7384f4e84e9c17f3fb8e (diff)
downloadunit-c838c3bd1580735e8020687f94e6307f13aba156.tar.gz
unit-c838c3bd1580735e8020687f94e6307f13aba156.tar.bz2
Node.js: added async request execution.
Diffstat (limited to 'src/nodejs/unit-http/http_server.js')
-rwxr-xr-xsrc/nodejs/unit-http/http_server.js29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js
index fa7b8e9b..ddacb420 100755
--- a/src/nodejs/unit-http/http_server.js
+++ b/src/nodejs/unit-http/http_server.js
@@ -232,7 +232,6 @@ ServerResponse.prototype.write = function write(chunk, encoding, callback) {
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,32 @@ 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(() => {
+ if (res.finished) {
+ unit_lib.unit_response_end(res);
+ }
+ });
+ });
+};
+
function connectionListener(socket) {
}
-
module.exports = {
STATUS_CODES: http.STATUS_CODES,
Server,