rock-req 5.0.1 → 5.0.3
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/README.md +0 -1
- package/index.js +6 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,6 @@ It also supports many features:
|
|
|
39
39
|
- Timeouts
|
|
40
40
|
- HTTPS / HTTP
|
|
41
41
|
- Composes well with npm packages for features like cookies, proxies, form data, & OAuth
|
|
42
|
-
- Typescript definition
|
|
43
42
|
- Keep 98% of the `simple-get` API (fork source)
|
|
44
43
|
|
|
45
44
|
Like NodeJS pipeline, when the callback is called, the request is 100% finished, even with streams.
|
package/index.js
CHANGED
|
@@ -85,7 +85,6 @@ function extend (defaultOptions = {}) {
|
|
|
85
85
|
res.resume() // Discard response, consume data until the end to free up memory. Mandatory!
|
|
86
86
|
return setTimeout(rock, opts.retryDelay, opts, cb) // retry later
|
|
87
87
|
}
|
|
88
|
-
|
|
89
88
|
// or redirect and leave
|
|
90
89
|
if (opts.followRedirects !== false && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
91
90
|
requestAbortedOrEnded = true // discard all new events which could come after for this request to avoid calling the callback
|
|
@@ -111,7 +110,6 @@ function extend (defaultOptions = {}) {
|
|
|
111
110
|
}
|
|
112
111
|
return rock(opts, cb)
|
|
113
112
|
}
|
|
114
|
-
|
|
115
113
|
// or read response and leave at the end
|
|
116
114
|
response = res
|
|
117
115
|
const contentEncoding = opts.method !== 'HEAD' ? (res.headers['content-encoding'] || '').toLowerCase() : ''
|
|
@@ -127,16 +125,18 @@ function extend (defaultOptions = {}) {
|
|
|
127
125
|
}
|
|
128
126
|
})
|
|
129
127
|
req.once('timeout', () => {
|
|
128
|
+
// This timeout event can come after the input pipeline is finished (ex. timeout with no body)
|
|
130
129
|
const _error = new Error('TimeoutError'); _error.code = 'ETIMEDOUT'
|
|
131
|
-
req.destroy() // we must destroy manually
|
|
132
|
-
|
|
130
|
+
req.destroy(_error) // we must destroy manually and send the error to the error listener to call onRequestEnd
|
|
131
|
+
})
|
|
132
|
+
req.once('error', (e) => {
|
|
133
|
+
onRequestEnd(e) // error can happen before pipeline is executed when some interceptor are used such as nock
|
|
134
|
+
req.destroy()
|
|
133
135
|
})
|
|
134
|
-
|
|
135
136
|
const _inputStream = isFnStream(body) ? body(opts) : Readable.from([body], { objectMode: false })
|
|
136
137
|
pipeline(_inputStream, req, (e) => {
|
|
137
138
|
if (e) onRequestEnd(e)
|
|
138
139
|
})
|
|
139
|
-
|
|
140
140
|
return req
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -153,6 +153,5 @@ function extend (defaultOptions = {}) {
|
|
|
153
153
|
rock.concat = rock
|
|
154
154
|
rock.defaults = _default
|
|
155
155
|
rock.extend = extend
|
|
156
|
-
|
|
157
156
|
return rock
|
|
158
157
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rock-req",
|
|
3
3
|
"description": "Zero dependencies (160 LOC) & rock-solid request library: http/https, reliable retry on failure, redirects, gzip/deflate/brotli, extensible, proxy, streams, JSON mode, forms, timeout",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.3",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "David Grelaud & Feross Aboukhadijeh"
|
|
7
7
|
},
|