| 503 | } |
| 504 | |
| 505 | _dispatch(options = {}) { |
| 506 | |
| 507 | return (req, res) => { |
| 508 | |
| 509 | // Create request |
| 510 | |
| 511 | const request = Request.generate(this.root, req, res, options); |
| 512 | |
| 513 | // Track socket request processing state |
| 514 | |
| 515 | if (this.settings.operations.cleanStop && |
| 516 | req.socket) { |
| 517 | |
| 518 | this.actives.set(req.socket, request); |
| 519 | const env = { core: this, req }; |
| 520 | res.on('finish', internals.onFinish.bind(res, env)); |
| 521 | } |
| 522 | |
| 523 | // Check load |
| 524 | |
| 525 | if (this.settings.load.sampleInterval) { |
| 526 | try { |
| 527 | this.heavy.check(); |
| 528 | } |
| 529 | catch (err) { |
| 530 | Bounce.rethrow(err, 'system'); |
| 531 | this._log(['load'], this.heavy.load); |
| 532 | request._reply(err); |
| 533 | return; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | request._execute(); |
| 538 | }; |
| 539 | } |
| 540 | |
| 541 | _createListener() { |
| 542 | |