[Poly > Request] Minor source cleanup

This commit is contained in:
Ducko 2022-04-21 14:00:04 +01:00
parent bce146927d
commit ac009a179e

View file

@ -1,12 +1,12 @@
const https = require('https');
// Generic polyfill for "request" npm package, wrapper for https
const nodeReq = ({ method, url, headers, qs, timeout, body, stream }) => new Promise((resolve) => {
const nodeReq = ({ method, url, headers, qs, timeout, body }) => new Promise((resolve) => {
let req;
try {
req = https.request(url + (qs != null ? `?${(new URLSearchParams(qs)).toString()}` : ''), { method, headers, timeout }, async (res) => {
const loc = res.headers.location;
if (loc) return resolve(await nodeReq({ url: loc, method, headers, timeout, body, stream }));
if (loc) return resolve(await nodeReq({ url: loc, method, headers, timeout, body }));
resolve(res);
});