@superhero/http-request 4.0.4 → 4.0.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.
Files changed (3) hide show
  1. package/README.md +6 -6
  2. package/index.js +16 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -331,14 +331,14 @@ tests 42
331
331
  suites 7
332
332
  pass 42
333
333
 
334
- ------------------------------------------------------------------------
334
+ ----------------------------------------------------------------------------------------
335
335
  file | line % | branch % | funcs % | uncovered lines
336
- ------------------------------------------------------------------------
337
- index.js | 97.16 | 92.45 | 95.12 | 487-496 524-526 662-668
336
+ ----------------------------------------------------------------------------------------
337
+ index.js | 94.05 | 91.74 | 92.86 | 496-505 533-535 671-677 702-705 735-755
338
338
  index.test.js | 100.00 | 97.67 | 100.00 |
339
- ------------------------------------------------------------------------
340
- all files | 98.41 | 94.79 | 98.10 |
341
- ------------------------------------------------------------------------
339
+ ----------------------------------------------------------------------------------------
340
+ all files | 96.57 | 94.36 | 97.17 |
341
+ ----------------------------------------------------------------------------------------
342
342
  ```
343
343
 
344
344
  ---
package/index.js CHANGED
@@ -48,20 +48,21 @@ import { setTimeout as wait } from 'node:timers/promises'
48
48
  */
49
49
  export default class Request
50
50
  {
51
- #config
52
-
53
51
  /**
54
52
  * @param {RequestOptions} config - The default/fallback request options/configurations.
55
53
  */
56
54
  constructor(config)
57
55
  {
58
- this.#config = 'string' === typeof config
59
- ? { base:config }
60
- : config || {}
56
+ config = config && JSON.parse(JSON.stringify(config))
57
+ config = 'string' === typeof config
58
+ ? { base: config }
59
+ : config || {}
60
+
61
+ const { base, url } = config
62
+ config.base = base ?? url
63
+ delete config.url
61
64
 
62
- const { base, url } = this.#config
63
- this.#config.base = base ?? url
64
- delete this.#config.url
65
+ Object.defineProperty(this, 'config', { enumerable: true, value: config })
65
66
  }
66
67
 
67
68
  /**
@@ -80,13 +81,13 @@ export default class Request
80
81
  {
81
82
  await this.close()
82
83
 
83
- const url = new URL(authority || this.#config.base)
84
+ const url = new URL(authority || this.config.base)
84
85
  authority = url.protocol + '//' + url.host
85
86
 
86
87
  this.http2Session = http2.connect(authority, ...args.slice(0, 1), () =>
87
88
  {
88
- this.#config.base = authority
89
- this.#config.url = url.pathname + url.search
89
+ this.config.base = authority
90
+ this.config.url = url.pathname + url.search
90
91
  this.http2Session.off('error', reject)
91
92
  accept()
92
93
  })
@@ -245,11 +246,11 @@ export default class Request
245
246
  options = { url:options }
246
247
  }
247
248
 
248
- if(this.#config.url && options.url)
249
+ if(this.config.url && options.url)
249
250
  {
250
251
  options.url = options.url[0] === '/'
251
252
  ? options.url
252
- : this.#config.url + options.url
253
+ : this.config.url + options.url
253
254
  }
254
255
 
255
256
  options = Object.assign(
@@ -261,7 +262,7 @@ export default class Request
261
262
  url : '',
262
263
  timeout : 30e3,
263
264
  retryOnStatus : []
264
- }, this.#config, options)
265
+ }, this.config, options)
265
266
 
266
267
  return options.retry
267
268
  ? this.#resolveRetryLoop(options)
@@ -731,7 +732,7 @@ export default class Request
731
732
 
732
733
  #contentTypeTextEventStream(body)
733
734
  {
734
- return body.split('\n\n').map((fields) =>
735
+ return body?.trim().split('\n\n').map((fields) =>
735
736
  {
736
737
  return Object.fromEntries(fields.split('\n').map((field) =>
737
738
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/http-request",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "description": "HTTP request component supporting HTTP 1.1 and HTTP 2.0",
5
5
  "keywords": [
6
6
  "http request",