@superhero/http-request 4.0.6 → 4.0.8

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.
Files changed (2) hide show
  1. package/index.js +13 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -75,7 +75,7 @@ export default class Request
75
75
  *
76
76
  * @see {@link https://nodejs.org/api/http2.html#http2connectauthority-options-listener}
77
77
  */
78
- connect(authority, ...args)
78
+ connect(authority, options)
79
79
  {
80
80
  return new Promise(async (accept, reject) =>
81
81
  {
@@ -83,16 +83,24 @@ export default class Request
83
83
 
84
84
  const url = new URL(authority || this.config.base)
85
85
  authority = url.protocol + '//' + url.host
86
+ options = Object.assign({}, this.config, options)
86
87
 
87
- this.http2Session = http2.connect(authority, ...args.slice(0, 1), () =>
88
+ this.http2Session = http2.connect(authority, options, () =>
88
89
  {
89
90
  this.config.base = authority
90
91
  this.config.url = url.pathname + url.search
91
- this.http2Session.off('error', reject)
92
+ this.http2Session.removeAllListeners('error')
92
93
  accept()
93
94
  })
94
95
 
95
- this.http2Session.once('error', reject)
96
+ this.http2Session.once('error', (reason) =>
97
+ {
98
+ const error = new Error(`Failed to connect to server over HTTP2 using authority: ${authority}`)
99
+ error.code = 'E_HTTP_REQUEST_CONNECT_ERROR'
100
+ error.cause = reason
101
+ reject(error)
102
+ })
103
+
96
104
  this.http2Session.once('close', () =>
97
105
  {
98
106
  this.http2Session.removeAllListeners()
@@ -346,7 +354,7 @@ export default class Request
346
354
  #resolveHttp1Client(options, method, headers, url, accept, reject)
347
355
  {
348
356
  const
349
- request = url.protocol === 'https:' ? https.request : http.request,
357
+ request = url.startsWith('https:') ? https.request : http.request,
350
358
  config = Object.assign({}, options, { headers }),
351
359
  upstream = request(url, config)
352
360
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/http-request",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "description": "HTTP request component supporting HTTP 1.1 and HTTP 2.0",
5
5
  "keywords": [
6
6
  "http request",