Skip to content

Commit

Permalink
fix #47
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrRogov committed Apr 26, 2019
1 parent d7da251 commit b81be31
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/requests/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ var httpRequest = function (options) {

var parsedUrl = url.parse(uri);
var protocol = parsedUrl.protocol.replace(':','');
var interface = protocol === 'http' ? http : https;
var protocolInterface = protocol === 'http' ? http : https;

var options = {
var internalOptions = {
hostname: parsedUrl.hostname,
port: parsedUrl.port,
path: parsedUrl.path,
Expand All @@ -51,27 +51,25 @@ var httpRequest = function (options) {
* is unsuitable for environments where requests are expected to be
* using end-to-end TLS.
*/
interface = http;
const proxyUrl = url.parse(process.env.http_proxy);
options = {
protocolInterface = http;
var proxyUrl = url.parse(process.env.http_proxy);
headers.host = parsedUrl.host;
internalOptions = {
hostname: proxyUrl.hostname,
port: proxyUrl.port,
path: parsedUrl.href,
method: method,
timeout: timeout,
headers: {
host: parsedUrl.host,
...headers,
}
headers: headers
};
}

var request = interface.request(options, function (res) {
var request = protocolInterface.request(internalOptions, function (res) {
var rawData = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
rawData += chunk;
})
});
res.on('end', function () {
switch (res.statusCode) {
case 200: // Success with content returned in response body.
Expand Down Expand Up @@ -115,8 +113,8 @@ var httpRequest = function (options) {
});
});

if (options.timeout) {
request.setTimeout(options.timeout, function () {
if (internalOptions.timeout) {
request.setTimeout(internalOptions.timeout, function () {
request.abort();
});
}
Expand Down

0 comments on commit b81be31

Please sign in to comment.