bare-http1 4.1.4 → 4.1.6

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/index.d.ts CHANGED
@@ -56,7 +56,7 @@ export interface HTTPIncomingMessage<
56
56
  setTimeout(ms: number, ontimeout?: () => void): this
57
57
  }
58
58
 
59
- export class HTTPIncomingMessage {
59
+ class HTTPIncomingMessage extends Readable {
60
60
  constructor(
61
61
  socket?: TCPSocket,
62
62
  headers?: Record<string, string | number>,
@@ -87,7 +87,7 @@ export interface HTTPOutgoingMessage<
87
87
  setTimeout(ms: number, ontimeout?: () => void): this
88
88
  }
89
89
 
90
- export class HTTPOutgoingMessage {
90
+ class HTTPOutgoingMessage extends Writable {
91
91
  constructor(socket?: TCPSocket)
92
92
  }
93
93
 
@@ -112,7 +112,7 @@ export interface HTTPAgent {
112
112
  destroy(): void
113
113
  }
114
114
 
115
- export class HTTPAgent {
115
+ class HTTPAgent {
116
116
  constructor(opts?: HTTPAgentOptions & TCPSocketOptions & TCPSocketConnectOptions)
117
117
 
118
118
  static global: HTTPAgent
@@ -134,7 +134,7 @@ export interface HTTPServer<M extends HTTPServerEvents = HTTPServerEvents> exten
134
134
  setTimeout(ms: number, ontimeout?: () => void): this
135
135
  }
136
136
 
137
- export class HTTPServer {
137
+ class HTTPServer extends TCPServer {
138
138
  constructor(
139
139
  opts?: HTTPServerConnectionOptions,
140
140
  onrequest?: (req: HTTPIncomingMessage, res: HTTPServerResponse) => void
@@ -159,7 +159,7 @@ export interface HTTPServerResponse extends HTTPOutgoingMessage {
159
159
  writeHead(statusCode: HTTPStatusCode, headers?: Record<string, string | number>): void
160
160
  }
161
161
 
162
- export class HTTPServerResponse {
162
+ class HTTPServerResponse extends HTTPOutgoingMessage {
163
163
  constructor(socket: TCPSocket, req: HTTPIncomingMessage, close: boolean)
164
164
  }
165
165
 
@@ -180,7 +180,7 @@ export interface HTTPServerConnection {
180
180
  readonly idle: boolean
181
181
  }
182
182
 
183
- export class HTTPServerConnection {
183
+ class HTTPServerConnection {
184
184
  constructor(server: HTTPServer, socket: TCPSocket, opts?: HTTPServerConnectionOptions)
185
185
 
186
186
  static for(socket: TCPSocket): HTTPServerConnection
@@ -207,7 +207,7 @@ export interface HTTPClientRequest<M extends HTTPClientRequestEvents = HTTPClien
207
207
  readonly headers: Record<string, string | number>
208
208
  }
209
209
 
210
- export class HTTPClientRequest {
210
+ class HTTPClientRequest extends HTTPOutgoingMessage {
211
211
  constructor(opts?: HTTPClientRequestOptions, onresponse?: () => void)
212
212
 
213
213
  constructor(onresponse: () => void)
@@ -228,7 +228,7 @@ export interface HTTPClientConnection {
228
228
  readonly idle: boolean
229
229
  }
230
230
 
231
- export class HTTPClientConnection {
231
+ class HTTPClientConnection {
232
232
  constructor(socket: TCPSocket, opts?: HTTPClientConnectionOptions)
233
233
 
234
234
  static for(socket: TCPSocket): HTTPClientConnection | null
@@ -18,6 +18,7 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
18
18
  const path = opts.path || '/'
19
19
  const host = (opts.host = opts.host || 'localhost')
20
20
  const port = (opts.port = opts.port || 80)
21
+ const headers = { host: host + (port === 80 ? '' : ':' + port), ...opts.headers }
21
22
 
22
23
  super()
23
24
 
@@ -25,7 +26,7 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
25
26
 
26
27
  this.method = method
27
28
  this.path = path
28
- this.headers = { host: host + ':' + port, ...opts.headers }
29
+ this.headers = headers
29
30
 
30
31
  this._chunked = method !== 'GET' && method !== 'HEAD'
31
32
 
@@ -1,4 +1,3 @@
1
- const tcp = require('bare-tcp')
2
1
  const { isEnded, isFinished, getStreamError } = require('bare-stream')
3
2
  const HTTPParser = require('bare-http-parser')
4
3
  const HTTPIncomingMessage = require('./incoming-message')
@@ -77,9 +76,7 @@ module.exports = class HTTPServerConnection {
77
76
 
78
77
  this._idle = true
79
78
 
80
- if (this.server._state & tcp.constants.state.CLOSING) {
81
- this.socket.destroy()
82
- }
79
+ if (this.server.closing) this.socket.destroy()
83
80
  })
84
81
 
85
82
  // Eagerly open the request stream
package/lib/server.js CHANGED
@@ -12,7 +12,9 @@ module.exports = class HTTPServer extends TCPServer {
12
12
 
13
13
  this._timeout = 0
14
14
 
15
- this.on('connection', (socket) => new HTTPServerConnection(this, socket, opts))
15
+ this.on('connection', (socket) => {
16
+ new HTTPServerConnection(this, socket, opts)
17
+ })
16
18
 
17
19
  if (onrequest) this.on('request', onrequest)
18
20
  }
@@ -32,10 +34,10 @@ module.exports = class HTTPServer extends TCPServer {
32
34
  close(onclose) {
33
35
  super.close(onclose)
34
36
 
35
- for (const socket of this._connections) {
37
+ for (const socket of this.connections) {
36
38
  const connection = HTTPServerConnection.for(socket)
37
39
 
38
- if (connection && connection.idle) {
40
+ if (connection === null || connection.idle) {
39
41
  socket.destroy()
40
42
  }
41
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-http1",
3
- "version": "4.1.4",
3
+ "version": "4.1.6",
4
4
  "description": "Native HTTP/1 library for JavaScript",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -39,7 +39,7 @@
39
39
  "bare-events": "^2.6.0",
40
40
  "bare-http-parser": "^1.0.0",
41
41
  "bare-stream": "^2.3.0",
42
- "bare-tcp": "^2.0.3"
42
+ "bare-tcp": "^2.2.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "bare-buffer": "^3.0.2",