Skip to content

Commit b3c3656

Browse files
committed
Replace request with make-fetch-happen
1 parent 14678b9 commit b3c3656

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

dl-tar/index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const {promises: fs} = require('fs');
88
const cancelablePump = require('../cancelable-pump/index.js');
99
const {Unpack} = require('tar');
1010
const isPlainObj = require('is-plain-obj');
11-
const request = require('request');
11+
const fetch = require('make-fetch-happen');
1212
const Observable = require('zen-observable');
1313

1414
class InternalUnpack extends Unpack {
@@ -184,21 +184,24 @@ module.exports = function dlTar(...args) {
184184
observer
185185
});
186186

187-
const pipe = [
188-
request({url, ...options, encoding: null})
189-
.on('response', function(response) {
190-
if (response.statusCode < 200 || 299 < response.statusCode) {
191-
this.emit('error', new Error(`${response.statusCode} ${response.statusMessage}`));
192-
return;
193-
}
187+
const {baseUrl, headers} = options;
188+
const {href} = new URL(url, baseUrl);
194189

195-
if (typeof response.headers['content-length'] === 'string') {
196-
response.headers['content-length'] = Number(response.headers['content-length']);
197-
}
190+
const res = await fetch(href, {headers}).then(response => {
198191

199-
unpackStream.url = response.request.uri.href;
200-
unpackStream.responseHeaders = response.headers;
201-
}),
192+
if (response.ok !== true) {
193+
throw new Error(`${response.status} ${response.statusText}`);
194+
}
195+
196+
unpackStream.url = response.url;
197+
unpackStream.responseHeaders = response.headers;
198+
199+
return response;
200+
201+
});
202+
203+
const pipe = [
204+
res.body,
202205
new Transform({
203206
transform(chunk, encoding, cb) {
204207
unpackStream.responseBytes += chunk.length;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"is-plain-obj": "^2.0.0",
2020
"log-symbols": "^3.0.0",
2121
"log-update": "^3.2.0",
22+
"make-fetch-happen": "^10.0.0",
2223
"minimist": "^1.2.0",
2324
"ms": "^2.1.2",
2425
"once": "^1.4.0",
2526
"pump": "^3.0.0",
26-
"request": "^2.88.0",
2727
"rimraf": "^2.6.3",
2828
"tar": "^6.1.11",
2929
"which": "^1.3.1",

0 commit comments

Comments
 (0)