bare-http1 4.1.2 → 4.1.3
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 +10 -33
- package/index.js +4 -2
- package/lib/agent.js +2 -9
- package/lib/client-connection.js +1 -4
- package/lib/client-request.js +2 -4
- package/lib/server-connection.js +2 -8
- package/lib/server-response.js +2 -5
- package/lib/server.js +1 -4
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -8,11 +8,7 @@ import {
|
|
|
8
8
|
} from 'bare-tcp'
|
|
9
9
|
import Buffer from 'bare-buffer'
|
|
10
10
|
import URL from 'bare-url'
|
|
11
|
-
import constants, {
|
|
12
|
-
HTTPMethod,
|
|
13
|
-
HTTPStatusCode,
|
|
14
|
-
HTTPStatusMessage
|
|
15
|
-
} from './lib/constants'
|
|
11
|
+
import constants, { HTTPMethod, HTTPStatusCode, HTTPStatusMessage } from './lib/constants'
|
|
16
12
|
import HTTPError from './lib/errors'
|
|
17
13
|
|
|
18
14
|
export {
|
|
@@ -111,18 +107,13 @@ export interface HTTPAgent {
|
|
|
111
107
|
|
|
112
108
|
getName(opts: { host: string; port: number }): string
|
|
113
109
|
|
|
114
|
-
addRequest(
|
|
115
|
-
req: HTTPClientRequest,
|
|
116
|
-
opts: TCPSocketOptions & TCPSocketConnectOptions
|
|
117
|
-
): void
|
|
110
|
+
addRequest(req: HTTPClientRequest, opts: TCPSocketOptions & TCPSocketConnectOptions): void
|
|
118
111
|
|
|
119
112
|
destroy(): void
|
|
120
113
|
}
|
|
121
114
|
|
|
122
115
|
export class HTTPAgent {
|
|
123
|
-
constructor(
|
|
124
|
-
opts?: HTTPAgentOptions & TCPSocketOptions & TCPSocketConnectOptions
|
|
125
|
-
)
|
|
116
|
+
constructor(opts?: HTTPAgentOptions & TCPSocketOptions & TCPSocketConnectOptions)
|
|
126
117
|
|
|
127
118
|
static global: HTTPAgent
|
|
128
119
|
}
|
|
@@ -137,8 +128,7 @@ export interface HTTPServerEvents extends TCPServerEvents {
|
|
|
137
128
|
timeout: [socket: TCPSocket]
|
|
138
129
|
}
|
|
139
130
|
|
|
140
|
-
export interface HTTPServer<M extends HTTPServerEvents = HTTPServerEvents>
|
|
141
|
-
extends TCPServer<M> {
|
|
131
|
+
export interface HTTPServer<M extends HTTPServerEvents = HTTPServerEvents> extends TCPServer<M> {
|
|
142
132
|
readonly timeout: number | undefined
|
|
143
133
|
|
|
144
134
|
setTimeout(ms: number, ontimeout?: () => void): this
|
|
@@ -150,9 +140,7 @@ export class HTTPServer {
|
|
|
150
140
|
onrequest?: (req: HTTPIncomingMessage, res: HTTPServerResponse) => void
|
|
151
141
|
)
|
|
152
142
|
|
|
153
|
-
constructor(
|
|
154
|
-
onrequest: (req: HTTPIncomingMessage, res: HTTPServerResponse) => void
|
|
155
|
-
)
|
|
143
|
+
constructor(onrequest: (req: HTTPIncomingMessage, res: HTTPServerResponse) => void)
|
|
156
144
|
}
|
|
157
145
|
|
|
158
146
|
export { HTTPServer as Server }
|
|
@@ -168,10 +156,7 @@ export interface HTTPServerResponse extends HTTPOutgoingMessage {
|
|
|
168
156
|
headers?: Record<string, string | number>
|
|
169
157
|
): void
|
|
170
158
|
|
|
171
|
-
writeHead(
|
|
172
|
-
statusCode: HTTPStatusCode,
|
|
173
|
-
headers?: Record<string, string | number>
|
|
174
|
-
): void
|
|
159
|
+
writeHead(statusCode: HTTPStatusCode, headers?: Record<string, string | number>): void
|
|
175
160
|
}
|
|
176
161
|
|
|
177
162
|
export class HTTPServerResponse {
|
|
@@ -194,11 +179,7 @@ export interface HTTPServerConnection {
|
|
|
194
179
|
}
|
|
195
180
|
|
|
196
181
|
export class HTTPServerConnection {
|
|
197
|
-
constructor(
|
|
198
|
-
server: HTTPServer,
|
|
199
|
-
socket: TCPSocket,
|
|
200
|
-
opts?: HTTPServerConnectionOptions
|
|
201
|
-
)
|
|
182
|
+
constructor(server: HTTPServer, socket: TCPSocket, opts?: HTTPServerConnectionOptions)
|
|
202
183
|
|
|
203
184
|
static for(socket: TCPSocket): HTTPServerConnection
|
|
204
185
|
}
|
|
@@ -217,9 +198,8 @@ export interface HTTPClientRequestOptions extends TCPSocketConnectOptions {
|
|
|
217
198
|
path?: string
|
|
218
199
|
}
|
|
219
200
|
|
|
220
|
-
export interface HTTPClientRequest<
|
|
221
|
-
|
|
222
|
-
> extends HTTPOutgoingMessage<M> {
|
|
201
|
+
export interface HTTPClientRequest<M extends HTTPClientRequestEvents = HTTPClientRequestEvents>
|
|
202
|
+
extends HTTPOutgoingMessage<M> {
|
|
223
203
|
readonly method: HTTPMethod
|
|
224
204
|
readonly path: string
|
|
225
205
|
readonly headers: Record<string, string | number>
|
|
@@ -251,10 +231,7 @@ export class HTTPClientConnection {
|
|
|
251
231
|
|
|
252
232
|
static for(socket: TCPSocket): HTTPClientConnection | null
|
|
253
233
|
|
|
254
|
-
static from(
|
|
255
|
-
socket: TCPSocket,
|
|
256
|
-
opts?: HTTPClientConnectionOptions
|
|
257
|
-
): HTTPClientConnection
|
|
234
|
+
static from(socket: TCPSocket, opts?: HTTPClientConnectionOptions): HTTPClientConnection
|
|
258
235
|
}
|
|
259
236
|
|
|
260
237
|
export { HTTPClientConnection as ClientConnection }
|
package/index.js
CHANGED
|
@@ -40,10 +40,12 @@ exports.request = function request(url, opts, onresponse) {
|
|
|
40
40
|
|
|
41
41
|
// For Node.js compatibility
|
|
42
42
|
opts.host = opts.hostname || opts.host
|
|
43
|
-
opts.port =
|
|
44
|
-
typeof opts.port === 'string' ? parseInt(opts.port, 10) : opts.port
|
|
43
|
+
opts.port = typeof opts.port === 'string' ? parseInt(opts.port, 10) : opts.port
|
|
45
44
|
}
|
|
46
45
|
|
|
46
|
+
// TODO: Renable the default global agent when hangs have been sorted
|
|
47
|
+
opts.agent = opts.agent || new exports.Agent()
|
|
48
|
+
|
|
47
49
|
return new exports.ClientRequest(opts, onresponse)
|
|
48
50
|
}
|
|
49
51
|
|
package/lib/agent.js
CHANGED
|
@@ -12,12 +12,7 @@ module.exports = class HTTPAgent extends EventEmitter {
|
|
|
12
12
|
this._sockets = new Map()
|
|
13
13
|
this._freeSockets = new Map()
|
|
14
14
|
|
|
15
|
-
this._keepAlive =
|
|
16
|
-
typeof keepAlive === 'number'
|
|
17
|
-
? keepAlive
|
|
18
|
-
: keepAlive
|
|
19
|
-
? keepAliveMsecs
|
|
20
|
-
: -1
|
|
15
|
+
this._keepAlive = typeof keepAlive === 'number' ? keepAlive : keepAlive ? keepAliveMsecs : -1
|
|
21
16
|
|
|
22
17
|
this._opts = { ...opts }
|
|
23
18
|
}
|
|
@@ -108,9 +103,7 @@ module.exports = class HTTPAgent extends EventEmitter {
|
|
|
108
103
|
}
|
|
109
104
|
|
|
110
105
|
_onremove(socket, name, all = true) {
|
|
111
|
-
for (const set of all
|
|
112
|
-
? [this._sockets, this._freeSockets]
|
|
113
|
-
: [this._sockets]) {
|
|
106
|
+
for (const set of all ? [this._sockets, this._freeSockets] : [this._sockets]) {
|
|
114
107
|
const sockets = set.get(name)
|
|
115
108
|
if (sockets === undefined) continue
|
|
116
109
|
|
package/lib/client-connection.js
CHANGED
|
@@ -90,10 +90,7 @@ module.exports = class HTTPClientConnection {
|
|
|
90
90
|
this.socket.emit('free')
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
-
if (
|
|
94
|
-
op.headers.connection &&
|
|
95
|
-
op.headers.connection.toLowerCase() === 'upgrade'
|
|
96
|
-
) {
|
|
93
|
+
if (op.headers.connection && op.headers.connection.toLowerCase() === 'upgrade') {
|
|
97
94
|
return this._onupgrade(this._parser.end())
|
|
98
95
|
}
|
|
99
96
|
|
package/lib/client-request.js
CHANGED
|
@@ -13,8 +13,7 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
|
|
|
13
13
|
|
|
14
14
|
opts = opts ? { ...opts } : {}
|
|
15
15
|
|
|
16
|
-
const agent =
|
|
17
|
-
opts.agent === false ? new HTTPAgent() : opts.agent || HTTPAgent.global
|
|
16
|
+
const agent = opts.agent === false ? new HTTPAgent() : opts.agent || HTTPAgent.global
|
|
18
17
|
const method = opts.method || 'GET'
|
|
19
18
|
const path = opts.path || '/'
|
|
20
19
|
const host = (opts.host = opts.host || 'localhost')
|
|
@@ -50,8 +49,7 @@ module.exports = class HTTPClientRequest extends HTTPOutgoingMessage {
|
|
|
50
49
|
const v = this.headers[name]
|
|
51
50
|
|
|
52
51
|
if (n === 'content-length') this._chunked = false
|
|
53
|
-
if (n === 'connection' && v && v.toLowerCase() === 'upgrade')
|
|
54
|
-
upgrade = true
|
|
52
|
+
if (n === 'connection' && v && v.toLowerCase() === 'upgrade') upgrade = true
|
|
55
53
|
|
|
56
54
|
h += `${httpCase(n)}: ${v}\r\n`
|
|
57
55
|
}
|
package/lib/server-connection.js
CHANGED
|
@@ -18,10 +18,7 @@ module.exports = class HTTPServerConnection {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
constructor(server, socket, opts = {}) {
|
|
21
|
-
const {
|
|
22
|
-
IncomingMessage = HTTPIncomingMessage,
|
|
23
|
-
ServerResponse = HTTPServerResponse
|
|
24
|
-
} = opts
|
|
21
|
+
const { IncomingMessage = HTTPIncomingMessage, ServerResponse = HTTPServerResponse } = opts
|
|
25
22
|
|
|
26
23
|
this.server = server
|
|
27
24
|
this.socket = socket
|
|
@@ -89,10 +86,7 @@ module.exports = class HTTPServerConnection {
|
|
|
89
86
|
this.req.resume()
|
|
90
87
|
this.req.pause()
|
|
91
88
|
|
|
92
|
-
if (
|
|
93
|
-
op.headers.connection &&
|
|
94
|
-
op.headers.connection.toLowerCase() === 'upgrade'
|
|
95
|
-
) {
|
|
89
|
+
if (op.headers.connection && op.headers.connection.toLowerCase() === 'upgrade') {
|
|
96
90
|
return this._onupgrade(this._parser.end())
|
|
97
91
|
}
|
|
98
92
|
|
package/lib/server-response.js
CHANGED
|
@@ -42,9 +42,7 @@ module.exports = class HTTPServerResponse extends HTTPOutgoingMessage {
|
|
|
42
42
|
'HTTP/1.1 ' +
|
|
43
43
|
this.statusCode +
|
|
44
44
|
' ' +
|
|
45
|
-
(this.statusMessage === null
|
|
46
|
-
? constants.status[this.statusCode]
|
|
47
|
-
: this.statusMessage) +
|
|
45
|
+
(this.statusMessage === null ? constants.status[this.statusCode] : this.statusMessage) +
|
|
48
46
|
'\r\n'
|
|
49
47
|
|
|
50
48
|
for (const name of Object.keys(this.headers)) {
|
|
@@ -52,8 +50,7 @@ module.exports = class HTTPServerResponse extends HTTPOutgoingMessage {
|
|
|
52
50
|
const v = this.headers[name]
|
|
53
51
|
|
|
54
52
|
if (n === 'content-length') this._chunked = false
|
|
55
|
-
if (n === 'connection' && v && v.toLowerCase() === 'close')
|
|
56
|
-
this._close = true
|
|
53
|
+
if (n === 'connection' && v && v.toLowerCase() === 'close') this._close = true
|
|
57
54
|
|
|
58
55
|
h += httpCase(n) + ': ' + v + '\r\n'
|
|
59
56
|
}
|
package/lib/server.js
CHANGED
|
@@ -12,10 +12,7 @@ module.exports = class HTTPServer extends TCPServer {
|
|
|
12
12
|
|
|
13
13
|
this._timeout = 0
|
|
14
14
|
|
|
15
|
-
this.on(
|
|
16
|
-
'connection',
|
|
17
|
-
(socket) => new HTTPServerConnection(this, socket, opts)
|
|
18
|
-
)
|
|
15
|
+
this.on('connection', (socket) => new HTTPServerConnection(this, socket, opts))
|
|
19
16
|
|
|
20
17
|
if (onrequest) this.on('request', onrequest)
|
|
21
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-http1",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3",
|
|
4
4
|
"description": "Native HTTP/1 library for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package": "./package.json",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"bare-url": "^2.1.3",
|
|
47
47
|
"brittle": "^3.3.0",
|
|
48
48
|
"prettier": "^3.4.1",
|
|
49
|
-
"prettier-config-
|
|
49
|
+
"prettier-config-holepunch": "^2.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"bare-buffer": "*",
|