bare-http1 4.1.6 → 4.2.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/index.d.ts +9 -2
- package/index.js +7 -1
- package/package.json +1 -1
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
|
@@ -30,7 +30,7 @@ exports.request = function request(url, opts, onresponse) {
|
|
|
30
30
|
if (typeof url === 'string') url = new URL(url)
|
|
31
31
|
|
|
32
32
|
if (isURL(url)) {
|
|
33
|
-
opts = opts ? { ...opts } : {}
|
|
33
|
+
opts = opts ? { ...url, ...opts } : { ...url }
|
|
34
34
|
|
|
35
35
|
opts.host = url.hostname
|
|
36
36
|
opts.path = url.pathname + url.search
|
|
@@ -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) {
|