bare-http1 4.1.5 → 4.2.0
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 +9 -2
- package/index.js +6 -0
- package/lib/client-request.js +2 -1
- package/lib/server-connection.js +1 -4
- package/lib/server.js +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -200,8 +200,9 @@ export interface HTTPClientRequestOptions extends TCPSocketConnectOptions {
|
|
|
200
200
|
path?: string
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
export interface HTTPClientRequest<
|
|
204
|
-
extends
|
|
203
|
+
export interface HTTPClientRequest<
|
|
204
|
+
M extends HTTPClientRequestEvents = HTTPClientRequestEvents
|
|
205
|
+
> extends HTTPOutgoingMessage<M> {
|
|
205
206
|
readonly method: HTTPMethod
|
|
206
207
|
readonly path: string
|
|
207
208
|
readonly headers: Record<string, string | number>
|
|
@@ -253,6 +254,12 @@ export function request(
|
|
|
253
254
|
onresponse?: (res: HTTPIncomingMessage) => void
|
|
254
255
|
): HTTPClientRequest
|
|
255
256
|
|
|
257
|
+
export function get(
|
|
258
|
+
url: URL | string,
|
|
259
|
+
opts?: HTTPClientRequestOptions,
|
|
260
|
+
onresponse?: (res: HTTPIncomingMessage) => void
|
|
261
|
+
): HTTPClientRequest
|
|
262
|
+
|
|
256
263
|
export function request(
|
|
257
264
|
url: URL | string,
|
|
258
265
|
onresponse: (res: HTTPIncomingMessage) => void
|
package/index.js
CHANGED
|
@@ -46,6 +46,12 @@ exports.request = function request(url, opts, onresponse) {
|
|
|
46
46
|
return new exports.ClientRequest(opts, onresponse)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
exports.get = function get(url, opts, onresponse) {
|
|
50
|
+
const req = exports.request(url, opts, onresponse)
|
|
51
|
+
req.end()
|
|
52
|
+
return req
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
// https://url.spec.whatwg.org/#default-port
|
|
50
56
|
function defaultPort(url) {
|
|
51
57
|
switch (url.protocol) {
|
package/lib/client-request.js
CHANGED
|
@@ -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 =
|
|
29
|
+
this.headers = headers
|
|
29
30
|
|
|
30
31
|
this._chunked = method !== 'GET' && method !== 'HEAD'
|
|
31
32
|
|
package/lib/server-connection.js
CHANGED
|
@@ -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.
|
|
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
|
@@ -34,7 +34,7 @@ module.exports = class HTTPServer extends TCPServer {
|
|
|
34
34
|
close(onclose) {
|
|
35
35
|
super.close(onclose)
|
|
36
36
|
|
|
37
|
-
for (const socket of this.
|
|
37
|
+
for (const socket of this.connections) {
|
|
38
38
|
const connection = HTTPServerConnection.for(socket)
|
|
39
39
|
|
|
40
40
|
if (connection === null || connection.idle) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-http1",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
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
|
|
42
|
+
"bare-tcp": "^2.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"bare-buffer": "^3.0.2",
|