http_server.js (869:1340e3539362) http_server.js (870:1e008ef94f43)
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6'use strict';
7
8const EventEmitter = require('events');

--- 274 unchanged lines hidden (view full) ---

283ServerRequest.prototype.listeners = function listeners() {
284 return [];
285};
286
287ServerRequest.prototype.resume = function resume() {
288 return [];
289};
290
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6'use strict';
7
8const EventEmitter = require('events');

--- 274 unchanged lines hidden (view full) ---

283ServerRequest.prototype.listeners = function listeners() {
284 return [];
285};
286
287ServerRequest.prototype.resume = function resume() {
288 return [];
289};
290
291/*
292 * The "on" method is overridden to defer reading data until user code is
293 * ready, that is (ev === "data"). This can occur after req.emit("end") is
294 * executed, since the user code can be scheduled asynchronously by Promises
295 * and so on. Passing the data is postponed by process.nextTick() until
296 * the "on" method caller completes.
297 */
298ServerRequest.prototype.on = function on(ev, fn) {
299 Server.prototype.on.call(this, ev, fn);
300
301 if (ev === "data") {
302 process.nextTick(function () {
303 if (this.server.buffer.length !== 0) {
304 this.emit("data", this.server.buffer);
305 }
306
307 }.bind(this));
308 }
309};
310
311ServerRequest.prototype.addListener = ServerRequest.prototype.on;
312
291function Server(requestListener) {
292 EventEmitter.call(this);
293
294 this.unit = new unit_lib.Unit();
295 this.unit.server = this;
296
297 this.unit.createServer();
298

--- 17 unchanged lines hidden (view full) ---

316 return this;
317};
318
319Server.prototype.listen = function () {
320 this.unit.listen();
321};
322
323Server.prototype.run_events = function (server, req, res) {
313function Server(requestListener) {
314 EventEmitter.call(this);
315
316 this.unit = new unit_lib.Unit();
317 this.unit.server = this;
318
319 this.unit.createServer();
320

--- 17 unchanged lines hidden (view full) ---

338 return this;
339};
340
341Server.prototype.listen = function () {
342 this.unit.listen();
343};
344
345Server.prototype.run_events = function (server, req, res) {
346 req.server = server;
347 res.server = server;
348 req.res = res;
349 res.req = req;
350
351 server.buffer = server.unit._read(req.socket.req_pointer);
352
324 /* Important!!! setImmediate starts the next iteration in Node.js loop. */
325 setImmediate(function () {
326 server.emit("request", req, res);
327
328 Promise.resolve().then(() => {
353 /* Important!!! setImmediate starts the next iteration in Node.js loop. */
354 setImmediate(function () {
355 server.emit("request", req, res);
356
357 Promise.resolve().then(() => {
329 let buf = server.unit._read(req.socket.req_pointer);
330
331 if (buf.length != 0) {
332 req.emit("data", buf);
333 }
334
358 req.emit("finish");
335 req.emit("end");
359 req.emit("end");
336 });
337
360
338 Promise.resolve().then(() => {
339 req.emit("finish");
340
341 if (res.finished) {
342 unit_lib.unit_response_end(res);
343 }
344 });
345 });
346};
347
348function connectionListener(socket) {
349}
350
351module.exports = {
352 STATUS_CODES: http.STATUS_CODES,
353 Server,
354 ServerResponse,
355 ServerRequest,
356 _connectionListener: connectionListener
357};
361 if (res.finished) {
362 unit_lib.unit_response_end(res);
363 }
364 });
365 });
366};
367
368function connectionListener(socket) {
369}
370
371module.exports = {
372 STATUS_CODES: http.STATUS_CODES,
373 Server,
374 ServerResponse,
375 ServerRequest,
376 _connectionListener: connectionListener
377};