bare-http1 3.8.0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/agent.js CHANGED
@@ -5,11 +5,7 @@ module.exports = class HTTPAgent {
5
5
  constructor (opts = {}) {
6
6
  const {
7
7
  keepAlive = false,
8
- keepAliveMsecs = 1000,
9
- maxSockets = Infinity,
10
- maxTotalSockets = Infinity,
11
- maxFreeSockets = 256,
12
- timeout = -1
8
+ keepAliveMsecs = 1000
13
9
  } = opts
14
10
 
15
11
  this._sockets = new Map()
@@ -18,10 +14,6 @@ module.exports = class HTTPAgent {
18
14
  this._keepAlive = typeof keepAlive === 'number' ? keepAlive : keepAlive ? keepAliveMsecs : -1
19
15
 
20
16
  this._opts = { ...opts }
21
- this._maxSockets = maxSockets
22
- this._maxTotalSockets = maxTotalSockets
23
- this._maxFreeSockets = maxFreeSockets
24
- this._timeout = timeout
25
17
  }
26
18
 
27
19
  createConnection (opts) {
@@ -65,6 +57,7 @@ module.exports = class HTTPAgent {
65
57
  socket
66
58
  .on('free', () => this._onfree(socket, name))
67
59
  .on('close', () => this._onremove(socket, name))
60
+ .on('timeout', () => this._ontimeout(socket, name))
68
61
  }
69
62
 
70
63
  let sockets = this._sockets.get(name)
@@ -116,5 +109,13 @@ module.exports = class HTTPAgent {
116
109
  }
117
110
  }
118
111
 
112
+ _ontimeout (socket, name) {
113
+ const sockets = this._freeSockets.get(name)
114
+ if (!sockets) return
115
+
116
+ if (sockets.delete(socket)) socket.destroy()
117
+ if (sockets.size === 0) this._freeSockets.delete(name)
118
+ }
119
+
119
120
  static global = new this({ keepAlive: 1000, timeout: 5000 })
120
121
  }
@@ -10,10 +10,7 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
10
10
 
11
11
  opts = opts ? { ...opts } : {}
12
12
 
13
- // TODO: Renable the default global agent when tests have been sorted
14
- // const agent = opts.agent === false ? new HTTPAgent() : opts.agent || HTTPAgent.global
15
-
16
- const agent = opts.agent || new HTTPAgent()
13
+ const agent = opts.agent === false ? new HTTPAgent() : opts.agent || HTTPAgent.global
17
14
  const method = opts.method || 'GET'
18
15
  const path = opts.path || '/'
19
16
  const host = opts.host = opts.host || 'localhost'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-http1",
3
- "version": "3.8.0",
3
+ "version": "3.8.1",
4
4
  "description": "Native HTTP/1 library for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",