Skip to content

Commit b81be31

Browse files
fix #47
1 parent d7da251 commit b81be31

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lib/requests/http.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ var httpRequest = function (options) {
3333

3434
var parsedUrl = url.parse(uri);
3535
var protocol = parsedUrl.protocol.replace(':','');
36-
var interface = protocol === 'http' ? http : https;
36+
var protocolInterface = protocol === 'http' ? http : https;
3737

38-
var options = {
38+
var internalOptions = {
3939
hostname: parsedUrl.hostname,
4040
port: parsedUrl.port,
4141
path: parsedUrl.path,
@@ -51,27 +51,25 @@ var httpRequest = function (options) {
5151
* is unsuitable for environments where requests are expected to be
5252
* using end-to-end TLS.
5353
*/
54-
interface = http;
55-
const proxyUrl = url.parse(process.env.http_proxy);
56-
options = {
54+
protocolInterface = http;
55+
var proxyUrl = url.parse(process.env.http_proxy);
56+
headers.host = parsedUrl.host;
57+
internalOptions = {
5758
hostname: proxyUrl.hostname,
5859
port: proxyUrl.port,
5960
path: parsedUrl.href,
6061
method: method,
6162
timeout: timeout,
62-
headers: {
63-
host: parsedUrl.host,
64-
...headers,
65-
}
63+
headers: headers
6664
};
6765
}
6866

69-
var request = interface.request(options, function (res) {
67+
var request = protocolInterface.request(internalOptions, function (res) {
7068
var rawData = '';
7169
res.setEncoding('utf8');
7270
res.on('data', function (chunk) {
7371
rawData += chunk;
74-
})
72+
});
7573
res.on('end', function () {
7674
switch (res.statusCode) {
7775
case 200: // Success with content returned in response body.
@@ -115,8 +113,8 @@ var httpRequest = function (options) {
115113
});
116114
});
117115

118-
if (options.timeout) {
119-
request.setTimeout(options.timeout, function () {
116+
if (internalOptions.timeout) {
117+
request.setTimeout(internalOptions.timeout, function () {
120118
request.abort();
121119
});
122120
}

0 commit comments

Comments
 (0)