From 5949633d03f7b68d21b053752658093dce7adefc Mon Sep 17 00:00:00 2001 From: Oj Date: Sat, 29 Jan 2022 10:09:55 +0000 Subject: [PATCH] [Poly > Request] Further cleanup tweaks --- polyfills/request.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/polyfills/request.js b/polyfills/request.js index cd98749..612fb34 100644 --- a/polyfills/request.js +++ b/polyfills/request.js @@ -2,15 +2,13 @@ const https = require('https'); const querystring = require("querystring"); // Generic polyfill for "request" npm package, wrapper for https -const nodeReq = ({ method, url, headers, qs, timeout, body, stream }) => new Promise((resolve, reject) => { +const nodeReq = ({ method, url, headers, qs, timeout, body, stream }) => new Promise((resolve) => { const fullUrl = `${url}${qs != null ? `?${querystring.stringify(qs)}` : ''}`; // With query string let req; try { req = https.request(fullUrl, { method, headers, timeout }, async (res) => { - if (res.statusCode === 301 || res.statusCode === 302) { // Redirect, recall function - return resolve(await nodeReq({ url: res.headers.location, method, headers, timeout, body, stream })); - } + if (res.statusCode === 301 || res.statusCode === 302) return resolve(await nodeReq({ url: res.headers.location, method, headers, timeout, body, stream })); resolve(res); }); @@ -26,11 +24,6 @@ const nodeReq = ({ method, url, headers, qs, timeout, body, stream }) => new Pro }); const request = (...args) => { - // We have to use ...args because we have to support all of these possible args: - // request(url, callback) - // request(options, callback) - // request(url, options, callback) - let options, callback; switch (args.length) { case 3: // request(url, options, callback)