| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c1abc8d commit 36fd3da
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ const { | |||
| 28 | 28 | ObjectKeys, | |
| 29 | 29 | ObjectPrototypeHasOwnProperty, | |
| 30 | 30 | ObjectSetPrototypeOf, | |
| 31 | + MathFloor, | ||
| 31 | 32 | Symbol, | |
| 32 | 33 | } = primordials; | |
| 33 | 34 | ||
@@ -118,6 +119,8 @@ function OutgoingMessage() { | |||
| 118 | 119 | this._header = null; | |
| 119 | 120 | this[kOutHeaders] = null; | |
| 120 | 121 | ||
| 122 | + this._keepAliveTimeout = 0; | ||
| 123 | + | ||
| 121 | 124 | this._onPendingData = noopPendingOutput; | |
| 122 | 125 | } | |
| 123 | 126 | ObjectSetPrototypeOf(OutgoingMessage.prototype, Stream.prototype); | |
@@ -419,6 +422,10 @@ function _storeHeader(firstLine, headers) { | |||
| 419 | 422 | (state.contLen || this.useChunkedEncodingByDefault || this.agent); | |
| 420 | 423 | if (shouldSendKeepAlive) { | |
| 421 | 424 | header += 'Connection: keep-alive\r\n'; | |
| 425 | + if (this._keepAliveTimeout) { | ||
| 426 | + const timeoutSeconds = MathFloor(this._keepAliveTimeout) / 1000; | ||
| 427 | + header += `Keep-Alive: timeout=${timeoutSeconds}\r\n`; | ||
| 428 | + } | ||
| 422 | 429 | } else { | |
| 423 | 430 | this._last = true; | |
| 424 | 431 | header += 'Connection: close\r\n'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -743,6 +743,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { | |||
| 743 | 743 | } | |
| 744 | 744 | ||
| 745 | 745 | const res = new server[kServerResponse](req); | |
| 746 | + res._keepAliveTimeout = server.keepAliveTimeout; | ||
| 746 | 747 | res._onPendingData = updateOutgoingData.bind(undefined, socket, state); | |
| 747 | 748 | ||
| 748 | 749 | res.shouldKeepAlive = keepAlive; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const http = require('http'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + const server = http.createServer(common.mustCall((req, res) => { | ||
| 8 | + const body = 'hello world\n'; | ||
| 9 | + | ||
| 10 | + res.writeHead(200, { 'Content-Length': body.length }); | ||
| 11 | + res.write(body); | ||
| 12 | + res.end(); | ||
| 13 | + })); | ||
| 14 | + server.keepAliveTimeout = 12000; | ||
| 15 | + | ||
| 16 | + const agent = new http.Agent({ maxSockets: 1, keepAlive: true }); | ||
| 17 | + | ||
| 18 | + server.listen(0, common.mustCall(function() { | ||
| 19 | + http.get({ | ||
| 20 | + path: '/', port: this.address().port, agent: agent | ||
| 21 | + }, common.mustCall((response) => { | ||
| 22 | + response.resume(); | ||
| 23 | + assert.strictEqual( | ||
| 24 | + response.headers['keep-alive'], 'timeout=12'); | ||
| 25 | + server.close(); | ||
| 26 | + agent.destroy(); | ||
| 27 | + })); | ||
| 28 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments