From f0926c03109207925d17e7c773a720c0eccfe872 Mon Sep 17 00:00:00 2001 From: Lee Powell Date: Wed, 23 Sep 2020 10:37:16 +0100 Subject: [PATCH] feat: support proxy --- index.js | 31 ++++++++++++++----------------- package.json | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 4b77987..e6c1165 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ var postcss = require('postcss'); -var hh = require('http-https'); +var request = require('request'); var isUrl = require('is-url'); var trim = require('lodash.trim'); var resolveRelative = require('resolve-relative-url'); @@ -11,7 +11,6 @@ var defaults = { userAgent: null, }; var space = postcss.list.space; -var url = require('url'); var urlRegexp = /url\(["']?.+?['"]?\)/g; function postcssImportUrl(options) { @@ -74,9 +73,12 @@ function resolveUrls(to, from) { } function createPromise(remoteFile, options) { - var reqOptions = url.parse(remoteFile); - reqOptions.headers = {}; - reqOptions.headers['connection'] = 'keep-alive'; + var reqOptions = { + url: remoteFile, + headers: { + connection: 'keep-alive', + }, + }; if (options.modernBrowser) { reqOptions.headers['user-agent'] = 'Mozilla/5.0 AppleWebKit/538.0 Chrome/65.0.0.0 Safari/538'; @@ -85,20 +87,15 @@ function createPromise(remoteFile, options) { reqOptions.headers['user-agent'] = String(options.userAgent); } function executor(resolve, reject) { - var request = hh.get(reqOptions, function (response) { - var body = ''; - response.on('data', function (chunk) { - body += chunk.toString(); - }); - response.on('end', function () { - resolve({ - body: body, - parent: remoteFile, - }); + request(remoteFile, reqOptions, function (error, response) { + if (error) { + return reject(error); + } + resolve({ + body: response.body, + parent: remoteFile, }); }); - request.on('error', reject); - request.end(); } return new Promise(executor); } diff --git a/package.json b/package.json index a92902d..cef957e 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,10 @@ "node": ">=10" }, "dependencies": { - "http-https": "^1.0.0", "is-url": "^1.2.4", "lodash.assign": "^4.2.0", "lodash.trim": "^4.5.1", + "request": "^2.88.2", "resolve-relative-url": "^1.0.0" }, "peerDependencies": {