@@ -9509,6 +9509,7 @@ var HttpCodes;
9509
9509
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
9510
9510
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
9511
9511
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
9512
+ HttpCodes[HttpCodes["TooManyRequests"] = 429] = "TooManyRequests";
9512
9513
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
9513
9514
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
9514
9515
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
@@ -9533,8 +9534,18 @@ function getProxyUrl(serverUrl) {
9533
9534
return proxyUrl ? proxyUrl.href : '';
9534
9535
}
9535
9536
exports.getProxyUrl = getProxyUrl;
9536
- const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
9537
- const HttpResponseRetryCodes = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout];
9537
+ const HttpRedirectCodes = [
9538
+ HttpCodes.MovedPermanently,
9539
+ HttpCodes.ResourceMoved,
9540
+ HttpCodes.SeeOther,
9541
+ HttpCodes.TemporaryRedirect,
9542
+ HttpCodes.PermanentRedirect
9543
+ ];
9544
+ const HttpResponseRetryCodes = [
9545
+ HttpCodes.BadGateway,
9546
+ HttpCodes.ServiceUnavailable,
9547
+ HttpCodes.GatewayTimeout
9548
+ ];
9538
9549
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
9539
9550
const ExponentialBackoffCeiling = 10;
9540
9551
const ExponentialBackoffTimeSlice = 5;
@@ -9659,18 +9670,22 @@ class HttpClient {
9659
9670
*/
9660
9671
async request(verb, requestUrl, data, headers) {
9661
9672
if (this._disposed) {
9662
- throw new Error(" Client has already been disposed." );
9673
+ throw new Error(' Client has already been disposed.' );
9663
9674
}
9664
9675
let parsedUrl = url.parse(requestUrl);
9665
9676
let info = this._prepareRequest(verb, parsedUrl, headers);
9666
9677
// Only perform retries on reads since writes may not be idempotent.
9667
- let maxTries = (this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1) ? this._maxRetries + 1 : 1;
9678
+ let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1
9679
+ ? this._maxRetries + 1
9680
+ : 1;
9668
9681
let numTries = 0;
9669
9682
let response;
9670
9683
while (numTries < maxTries) {
9671
9684
response = await this.requestRaw(info, data);
9672
9685
// Check if it's an authentication challenge
9673
- if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) {
9686
+ if (response &&
9687
+ response.message &&
9688
+ response.message.statusCode === HttpCodes.Unauthorized) {
9674
9689
let authenticationHandler;
9675
9690
for (let i = 0; i < this.handlers.length; i++) {
9676
9691
if (this.handlers[i].canHandleAuthentication(response)) {
@@ -9688,21 +9703,32 @@ class HttpClient {
9688
9703
}
9689
9704
}
9690
9705
let redirectsRemaining = this._maxRedirects;
9691
- while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1
9692
- && this._allowRedirects
9693
- && redirectsRemaining > 0) {
9694
- const redirectUrl = response.message.headers[" location" ];
9706
+ while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 &&
9707
+ this._allowRedirects &&
9708
+ redirectsRemaining > 0) {
9709
+ const redirectUrl = response.message.headers[' location' ];
9695
9710
if (!redirectUrl) {
9696
9711
// if there's no location to redirect to, we won't
9697
9712
break;
9698
9713
}
9699
9714
let parsedRedirectUrl = url.parse(redirectUrl);
9700
- if (parsedUrl.protocol == 'https:' && parsedUrl.protocol != parsedRedirectUrl.protocol && !this._allowRedirectDowngrade) {
9701
- throw new Error("Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.");
9715
+ if (parsedUrl.protocol == 'https:' &&
9716
+ parsedUrl.protocol != parsedRedirectUrl.protocol &&
9717
+ !this._allowRedirectDowngrade) {
9718
+ throw new Error('Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.');
9702
9719
}
9703
9720
// we need to finish reading the response before reassigning response
9704
9721
// which will leak the open socket.
9705
9722
await response.readBody();
9723
+ // strip authorization header if redirected to a different hostname
9724
+ if (parsedRedirectUrl.hostname !== parsedUrl.hostname) {
9725
+ for (let header in headers) {
9726
+ // header names are case insensitive
9727
+ if (header.toLowerCase() === 'authorization') {
9728
+ delete headers[header];
9729
+ }
9730
+ }
9731
+ }
9706
9732
// let's make the request with the new redirectUrl
9707
9733
info = this._prepareRequest(verb, parsedRedirectUrl, headers);
9708
9734
response = await this.requestRaw(info, data);
@@ -9753,8 +9779,8 @@ class HttpClient {
9753
9779
*/
9754
9780
requestRawWithCallback(info, data, onResult) {
9755
9781
let socket;
9756
- if (typeof ( data) === 'string') {
9757
- info.options.headers[" Content-Length" ] = Buffer.byteLength(data, 'utf8');
9782
+ if (typeof data === 'string') {
9783
+ info.options.headers[' Content-Length' ] = Buffer.byteLength(data, 'utf8');
9758
9784
}
9759
9785
let callbackCalled = false;
9760
9786
let handleResult = (err, res) => {
@@ -9767,7 +9793,7 @@ class HttpClient {
9767
9793
let res = new HttpClientResponse(msg);
9768
9794
handleResult(null, res);
9769
9795
});
9770
- req.on('socket', ( sock) => {
9796
+ req.on('socket', sock => {
9771
9797
socket = sock;
9772
9798
});
9773
9799
// If we ever get disconnected, we want the socket to timeout eventually
@@ -9782,10 +9808,10 @@ class HttpClient {
9782
9808
// res should have headers
9783
9809
handleResult(err, null);
9784
9810
});
9785
- if (data && typeof ( data) === 'string') {
9811
+ if (data && typeof data === 'string') {
9786
9812
req.write(data, 'utf8');
9787
9813
}
9788
- if (data && typeof ( data) !== 'string') {
9814
+ if (data && typeof data !== 'string') {
9789
9815
data.on('close', function () {
9790
9816
req.end();
9791
9817
});
@@ -9812,31 +9838,34 @@ class HttpClient {
9812
9838
const defaultPort = usingSsl ? 443 : 80;
9813
9839
info.options = {};
9814
9840
info.options.host = info.parsedUrl.hostname;
9815
- info.options.port = info.parsedUrl.port ? parseInt(info.parsedUrl.port) : defaultPort;
9816
- info.options.path = (info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
9841
+ info.options.port = info.parsedUrl.port
9842
+ ? parseInt(info.parsedUrl.port)
9843
+ : defaultPort;
9844
+ info.options.path =
9845
+ (info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
9817
9846
info.options.method = method;
9818
9847
info.options.headers = this._mergeHeaders(headers);
9819
9848
if (this.userAgent != null) {
9820
- info.options.headers[" user-agent" ] = this.userAgent;
9849
+ info.options.headers[' user-agent' ] = this.userAgent;
9821
9850
}
9822
9851
info.options.agent = this._getAgent(info.parsedUrl);
9823
9852
// gives handlers an opportunity to participate
9824
9853
if (this.handlers) {
9825
- this.handlers.forEach(( handler) => {
9854
+ this.handlers.forEach(handler => {
9826
9855
handler.prepareRequest(info.options);
9827
9856
});
9828
9857
}
9829
9858
return info;
9830
9859
}
9831
9860
_mergeHeaders(headers) {
9832
- const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
9861
+ const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (( c[k.toLowerCase()] = obj[k]) , c), {});
9833
9862
if (this.requestOptions && this.requestOptions.headers) {
9834
9863
return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers));
9835
9864
}
9836
9865
return lowercaseKeys(headers || {});
9837
9866
}
9838
9867
_getExistingOrDefaultHeader(additionalHeaders, header, _default) {
9839
- const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
9868
+ const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (( c[k.toLowerCase()] = obj[k]) , c), {});
9840
9869
let clientHeader;
9841
9870
if (this.requestOptions && this.requestOptions.headers) {
9842
9871
clientHeader = lowercaseKeys(this.requestOptions.headers)[header];
@@ -9874,7 +9903,7 @@ class HttpClient {
9874
9903
proxyAuth: proxyUrl.auth,
9875
9904
host: proxyUrl.hostname,
9876
9905
port: proxyUrl.port
9877
- },
9906
+ }
9878
9907
};
9879
9908
let tunnelAgent;
9880
9909
const overHttps = proxyUrl.protocol === 'https:';
@@ -9901,7 +9930,9 @@ class HttpClient {
9901
9930
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
9902
9931
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
9903
9932
// we have to cast it to any and change it directly
9904
- agent.options = Object.assign(agent.options || {}, { rejectUnauthorized: false });
9933
+ agent.options = Object.assign(agent.options || {}, {
9934
+ rejectUnauthorized: false
9935
+ });
9905
9936
}
9906
9937
return agent;
9907
9938
}
@@ -9962,7 +9993,7 @@ class HttpClient {
9962
9993
msg = contents;
9963
9994
}
9964
9995
else {
9965
- msg = " Failed request: (" + statusCode + ")" ;
9996
+ msg = ' Failed request: (' + statusCode + ')' ;
9966
9997
}
9967
9998
let err = new Error(msg);
9968
9999
// attach statusCode and body obj (if available) to the error object
@@ -28241,12 +28272,10 @@ function getProxyUrl(reqUrl) {
28241
28272
}
28242
28273
let proxyVar;
28243
28274
if (usingSsl) {
28244
- proxyVar = process.env["https_proxy"] ||
28245
- process.env["HTTPS_PROXY"];
28275
+ proxyVar = process.env['https_proxy'] || process.env['HTTPS_PROXY'];
28246
28276
}
28247
28277
else {
28248
- proxyVar = process.env["http_proxy"] ||
28249
- process.env["HTTP_PROXY"];
28278
+ proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY'];
28250
28279
}
28251
28280
if (proxyVar) {
28252
28281
proxyUrl = url.parse(proxyVar);
@@ -28258,7 +28287,7 @@ function checkBypass(reqUrl) {
28258
28287
if (!reqUrl.hostname) {
28259
28288
return false;
28260
28289
}
28261
- let noProxy = process.env[" no_proxy" ] || process.env[" NO_PROXY" ] || '';
28290
+ let noProxy = process.env[' no_proxy' ] || process.env[' NO_PROXY' ] || '';
28262
28291
if (!noProxy) {
28263
28292
return false;
28264
28293
}
@@ -28279,7 +28308,10 @@ function checkBypass(reqUrl) {
28279
28308
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
28280
28309
}
28281
28310
// Compare request host against noproxy
28282
- for (let upperNoProxyItem of noProxy.split(',').map(x => x.trim().toUpperCase()).filter(x => x)) {
28311
+ for (let upperNoProxyItem of noProxy
28312
+ .split(',')
28313
+ .map(x => x.trim().toUpperCase())
28314
+ .filter(x => x)) {
28283
28315
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
28284
28316
return true;
28285
28317
}
0 commit comments