rock-req 5.1.0 → 5.1.2

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 +20 -23
  2. package/index.js +3 -3
  3. package/package.json +4 -3
package/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
 
2
2
  <p align="center">
3
- <img src="https://raw.githubusercontent.com/carboneio/rock-req/master/doc/rock-req-logo.svg" alt="rock-req logo" height="120"/>
3
+ <img src="https://raw.githubusercontent.com/carboneio/rock-req/master/doc/rock-req-logo.svg" alt="rock-req logo" height="150"/>
4
4
  </p>
5
5
 
6
- <h1 align="center" style="border-bottom:none; font-size: 2.2em;">Rock-req.js</h1>
6
+ <h1 align="center" style="border-bottom:none;">Rock-req</h1>
7
7
 
8
8
  <p align="center">⭐️⭐️ Ensure your HTTP requests always reach their destination as <b>efficiently</b> as possible! ⭐️⭐️</p>
9
+ <p align="center">Tested on Mac, Linux, Windows with NodeJS 16, 18, 19, 20</p>
9
10
 
10
11
  [![npm][npm-image]][npm-url] [![ci][ci-image]][ci-url] [![javascript style guide][standard-image]][standard-url]
11
12
 
@@ -53,24 +54,26 @@ When the callback is called, the request is 100% finished, even with streams.
53
54
  Stop using "slow by-default" and "false-light" HTTP request libraries!
54
55
 
55
56
 
56
- | Library | Speed | Size deps inc. |
57
- | ------------ |-----------------:| --------------:|
58
- | rock-req 🙋‍♂️ | 21797 req/s | 144 LOC |
59
- | simple-get | 3260 req/s | 317 LOC |
60
- | axios | 4910 req/s | 13983 LOC |
61
- | got | 1762 req/s | 9227 LOC |
62
- | fetch | 2102 req/s | 13334 LOC |
63
- | request | 1869 req/s | 46572 LOC |
64
- | superagent | 2100 req/s | 16109 LOC |
65
- | phin | 1164 req/s | 331 LOC |
66
- | undici* | 24378 req/s | 16225 LOC |
57
+ | Library | NodeJS 16 | NodeJS 18 | NodeJS 20* | Size deps inc. |
58
+ | ------------ |--------------:|--------------:| --------------:| --------------:|
59
+ | rock-req 🙋‍♂️ | 22816 req/s | 21797 req/s | 21964 req/s | 144 LOC |
60
+ | simple-get | 2937 req/s | 3260 req/s | 21258 req/s | 317 LOC |
61
+ | axios | 5090 req/s | 4910 req/s | 3196 req/s | 13983 LOC |
62
+ | got | 2163 req/s | 1762 req/s | 9961 req/s | 9227 LOC |
63
+ | fetch | 2101 req/s | 2102 req/s | 2020 req/s | 13334 LOC |
64
+ | request | 2249 req/s | 1869 req/s | 15815 req/s | 46572 LOC |
65
+ | superagent | 2776 req/s | 2100 req/s | 2895 req/s | 16109 LOC |
66
+ | phin | 3178 req/s | 1164 req/s | 21299 req/s | 331 LOC |
67
+ | _undici_* | 24095 req/s | 24378 req/s | 24191 req/s | 16225 LOC |
67
68
 
68
69
 
70
+ > NodeJS 20 activates HTTP keep-alive by default, like `rock-req`
71
+
69
72
  > `undici` is a low-level API, faster alternative to the native NodeJS http module. It is the glass ceiling limit for NodeJS.
70
73
 
71
- > `rock-req` uses only the native NodeJS http module and provides many high-level features, a lot more than `phin` and `simple-get` with fewer lines
74
+ > `rock-req` uses only the native NodeJS http module and provides many high-level features, a lot more than `phin` and `simple-get` with fewer lines of code.
72
75
 
73
- > Tested with NodeJS 18.x LTS on Macbook Pro M1 Max
76
+ > Tested on Macbook Pro M1 Max
74
77
 
75
78
 
76
79
  ## Install
@@ -592,14 +595,8 @@ Rock-req is a fork of [simple-get](https://github.com/feross/simple-get)
592
595
  ## TODO:
593
596
 
594
597
  - [ ] replace deprecated `url.parse` by `new URL` but new URL is slower than url.parse. Let's see if Node 20 LTS is faster
595
- - [ ] add advanced timeout (response timeout)
596
- - [ ] test prevError
597
- - [ ] test HTTP abort signal option
598
- - [ ] test input stream error with 502 error retry. Does stream.resume destroy all streams?
599
- - [ ] promisify
600
- - [ ] typescript type
601
- - [ ] NodesJS 19 doesn't need agent.timeout to exit https://github.com/nodejs/node/issues/47228 https://github.com/nodejs/node/issues/2642
602
-
598
+ - [ ] promisify ?
599
+ - [ ] typescript type ?
603
600
 
604
601
  # Supporters
605
602
 
package/index.js CHANGED
@@ -71,19 +71,19 @@ function extend (defaultOptions = {}) {
71
71
  streamToCleanOnError.forEach(s => s.destroy(err))
72
72
  if (opts.retryOnError.indexOf(err?.code) !== -1 && --opts.remainingRetry > 0) {
73
73
  opts.prevError = err
74
- return setTimeout(rock, opts.retryDelay, opts, cb) // retry in 100ms
74
+ return setTimeout(rock, opts.retryDelay, opts, cb) // retry
75
75
  }
76
76
  return cb(err)
77
77
  }
78
78
  let data = Buffer.concat(chunks)
79
79
  if (opts.json) {
80
- try { data = JSON.parse(data.toString()) } catch (e) { return cb(e, response, data) }
80
+ try { data = data.length > 0 ? JSON.parse(data.toString()) : null } catch (e) { return cb(e, response, data) }
81
81
  }
82
82
  cb(null, response, data)
83
83
  }
84
84
  function listen (stream, isLast = false) {
85
85
  streamToCleanOnError.push(stream)
86
- stream.once('error', onRequestEnd)
86
+ stream.on('error', onRequestEnd) // do not use once()! A stream can emit mutiple error event
87
87
  stream.once('close', () => {
88
88
  if (stream.readableEnded === false || stream.writableEnded === false) return onRequestEnd(new Error('ERR_STREAM_PREMATURE_CLOSE'))
89
89
  if (isLast === true) return onRequestEnd()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rock-req",
3
- "description": "Zero deps (160 LOC) & ultra-fast request library: http/https, reliable retry on failure, redirects, gzip/deflate/brotli, extensible, proxy, streams, JSON mode, forms, timeout",
4
- "version": "5.1.0",
3
+ "description": "Ultra-light (150 LOC, No dependencies) & Ultra-fast request library with reliable retry on failure, http/https, redirects, gzip/deflate/brotli, extensible, proxy, streams, JSON mode, forms, timeout",
4
+ "version": "5.1.2",
5
5
  "author": {
6
6
  "name": "David Grelaud & Feross Aboukhadijeh"
7
7
  },
@@ -42,6 +42,7 @@
42
42
  "url": "git://github.com/carboneio/rock-req.git"
43
43
  },
44
44
  "scripts": {
45
- "test": "tape test/*.js"
45
+ "test": "tape test/*.js",
46
+ "standard": "node_modules/.bin/standard"
46
47
  }
47
48
  }