bare-http1 3.8.1 → 3.8.2

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.
@@ -1,4 +1,5 @@
1
1
  const tcp = require('bare-tcp')
2
+ const { isEnded, isFinished, getStreamError } = require('bare-stream')
2
3
  const HTTPIncomingMessage = require('./incoming-message')
3
4
  const HTTPServerResponse = require('./server-response')
4
5
  const constants = require('./constants')
@@ -33,13 +34,14 @@ module.exports = class HTTPServerConnection {
33
34
  this._buffer = null
34
35
  this._idle = true
35
36
 
36
- this._onerror = this._onerror.bind(this)
37
+ this._onclose = this._onclose.bind(this)
37
38
  this._ondata = this._ondata.bind(this)
38
39
  this._ondrain = this._ondrain.bind(this)
39
40
  this._ontimeout = this._ontimeout.bind(this)
40
41
 
41
42
  socket
42
- .on('error', this._onerror)
43
+ .on('error', noop)
44
+ .on('close', this._onclose)
43
45
  .on('data', this._ondata)
44
46
  .on('drain', this._ondrain)
45
47
  .on('timeout', this._ontimeout)
@@ -53,8 +55,11 @@ module.exports = class HTTPServerConnection {
53
55
  return this._idle
54
56
  }
55
57
 
56
- _onerror (err) {
57
- this.socket.destroy(err)
58
+ _onclose () {
59
+ if (this.req && !isEnded(this.req)) this.req.destroy()
60
+ if (this.res && !isFinished(this.res)) this.res.destroy()
61
+ const err = getStreamError(this.socket)
62
+ if (err) this.socket.destroy(err)
58
63
  }
59
64
 
60
65
  _ondata (data) {
@@ -232,7 +237,8 @@ module.exports = class HTTPServerConnection {
232
237
 
233
238
  _ondetach () {
234
239
  this.socket
235
- .off('error', this._onerror)
240
+ .off('error', noop)
241
+ .off('close', this._onclose)
236
242
  .off('data', this._ondata)
237
243
  .off('drain', this._ondrain)
238
244
  .off('timeout', this._ontimeout)
@@ -240,3 +246,5 @@ module.exports = class HTTPServerConnection {
240
246
  HTTPServerConnection._connections.delete(this.socket)
241
247
  }
242
248
  }
249
+
250
+ function noop () {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-http1",
3
- "version": "3.8.1",
3
+ "version": "3.8.2",
4
4
  "description": "Native HTTP/1 library for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -26,7 +26,7 @@
26
26
  "homepage": "https://github.com/holepunchto/bare-http1#readme",
27
27
  "dependencies": {
28
28
  "bare-events": "^2.0.0",
29
- "bare-stream": "^2.0.0",
29
+ "bare-stream": "^2.3.0",
30
30
  "bare-tcp": "^1.8.0"
31
31
  },
32
32
  "devDependencies": {