piral-cli 0.14.8-beta.3480 → 0.14.8-beta.3483
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/external/index.js +60 -22
- package/package.json +1 -1
package/lib/external/index.js
CHANGED
|
@@ -46043,7 +46043,7 @@ events.forEach(function (event) {
|
|
|
46043
46043
|
// Error types with codes
|
|
46044
46044
|
var RedirectionError = createErrorType(
|
|
46045
46045
|
"ERR_FR_REDIRECTION_FAILURE",
|
|
46046
|
-
""
|
|
46046
|
+
"Redirected request failed"
|
|
46047
46047
|
);
|
|
46048
46048
|
var TooManyRedirectsError = createErrorType(
|
|
46049
46049
|
"ERR_FR_TOO_MANY_REDIRECTS",
|
|
@@ -46172,10 +46172,8 @@ RedirectableRequest.prototype.removeHeader = function (name) {
|
|
|
46172
46172
|
// Global timeout for all underlying requests
|
|
46173
46173
|
RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
|
46174
46174
|
var self = this;
|
|
46175
|
-
if (callback) {
|
|
46176
|
-
this.on("timeout", callback);
|
|
46177
|
-
}
|
|
46178
46175
|
|
|
46176
|
+
// Destroys the socket on timeout
|
|
46179
46177
|
function destroyOnTimeout(socket) {
|
|
46180
46178
|
socket.setTimeout(msecs);
|
|
46181
46179
|
socket.removeListener("timeout", socket.destroy);
|
|
@@ -46194,18 +46192,32 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
|
|
46194
46192
|
destroyOnTimeout(socket);
|
|
46195
46193
|
}
|
|
46196
46194
|
|
|
46197
|
-
//
|
|
46195
|
+
// Stops a timeout from triggering
|
|
46198
46196
|
function clearTimer() {
|
|
46199
|
-
|
|
46197
|
+
// Clear the timeout
|
|
46198
|
+
if (self._timeout) {
|
|
46199
|
+
clearTimeout(self._timeout);
|
|
46200
|
+
self._timeout = null;
|
|
46201
|
+
}
|
|
46202
|
+
|
|
46203
|
+
// Clean up all attached listeners
|
|
46204
|
+
self.removeListener("abort", clearTimer);
|
|
46205
|
+
self.removeListener("error", clearTimer);
|
|
46206
|
+
self.removeListener("response", clearTimer);
|
|
46200
46207
|
if (callback) {
|
|
46201
46208
|
self.removeListener("timeout", callback);
|
|
46202
46209
|
}
|
|
46203
|
-
if (!
|
|
46210
|
+
if (!self.socket) {
|
|
46204
46211
|
self._currentRequest.removeListener("socket", startTimer);
|
|
46205
46212
|
}
|
|
46206
46213
|
}
|
|
46207
46214
|
|
|
46208
|
-
//
|
|
46215
|
+
// Attach callback if passed
|
|
46216
|
+
if (callback) {
|
|
46217
|
+
this.on("timeout", callback);
|
|
46218
|
+
}
|
|
46219
|
+
|
|
46220
|
+
// Start the timer if or when the socket is opened
|
|
46209
46221
|
if (this.socket) {
|
|
46210
46222
|
startTimer(this.socket);
|
|
46211
46223
|
}
|
|
@@ -46213,9 +46225,11 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
|
|
46213
46225
|
this._currentRequest.once("socket", startTimer);
|
|
46214
46226
|
}
|
|
46215
46227
|
|
|
46228
|
+
// Clean up on events
|
|
46216
46229
|
this.on("socket", destroyOnTimeout);
|
|
46217
|
-
this.
|
|
46218
|
-
this.
|
|
46230
|
+
this.on("abort", clearTimer);
|
|
46231
|
+
this.on("error", clearTimer);
|
|
46232
|
+
this.on("response", clearTimer);
|
|
46219
46233
|
|
|
46220
46234
|
return this;
|
|
46221
46235
|
};
|
|
@@ -46379,19 +46393,33 @@ RedirectableRequest.prototype._processResponse = function (response) {
|
|
|
46379
46393
|
}
|
|
46380
46394
|
|
|
46381
46395
|
// Drop the Host header, as the redirect might lead to a different host
|
|
46382
|
-
var
|
|
46383
|
-
|
|
46396
|
+
var currentHostHeader = removeMatchingHeaders(/^host$/i, this._options.headers);
|
|
46397
|
+
|
|
46398
|
+
// If the redirect is relative, carry over the host of the last request
|
|
46399
|
+
var currentUrlParts = url.parse(this._currentUrl);
|
|
46400
|
+
var currentHost = currentHostHeader || currentUrlParts.host;
|
|
46401
|
+
var currentUrl = /^\w+:/.test(location) ? this._currentUrl :
|
|
46402
|
+
url.format(Object.assign(currentUrlParts, { host: currentHost }));
|
|
46403
|
+
|
|
46404
|
+
// Determine the URL of the redirection
|
|
46405
|
+
var redirectUrl;
|
|
46406
|
+
try {
|
|
46407
|
+
redirectUrl = url.resolve(currentUrl, location);
|
|
46408
|
+
}
|
|
46409
|
+
catch (cause) {
|
|
46410
|
+
this.emit("error", new RedirectionError(cause));
|
|
46411
|
+
return;
|
|
46412
|
+
}
|
|
46384
46413
|
|
|
46385
46414
|
// Create the redirected request
|
|
46386
|
-
var redirectUrl = url.resolve(this._currentUrl, location);
|
|
46387
46415
|
debug("redirecting to", redirectUrl);
|
|
46388
46416
|
this._isRedirect = true;
|
|
46389
46417
|
var redirectUrlParts = url.parse(redirectUrl);
|
|
46390
46418
|
Object.assign(this._options, redirectUrlParts);
|
|
46391
46419
|
|
|
46392
|
-
// Drop the
|
|
46393
|
-
if (redirectUrlParts.
|
|
46394
|
-
removeMatchingHeaders(/^authorization$/i, this._options.headers);
|
|
46420
|
+
// Drop the confidential headers when redirecting to another domain
|
|
46421
|
+
if (!(redirectUrlParts.host === currentHost || isSubdomainOf(redirectUrlParts.host, currentHost))) {
|
|
46422
|
+
removeMatchingHeaders(/^(?:authorization|cookie)$/i, this._options.headers);
|
|
46395
46423
|
}
|
|
46396
46424
|
|
|
46397
46425
|
// Evaluate the beforeRedirect callback
|
|
@@ -46412,9 +46440,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
|
|
|
46412
46440
|
this._performRequest();
|
|
46413
46441
|
}
|
|
46414
46442
|
catch (cause) {
|
|
46415
|
-
|
|
46416
|
-
error.cause = cause;
|
|
46417
|
-
this.emit("error", error);
|
|
46443
|
+
this.emit("error", new RedirectionError(cause));
|
|
46418
46444
|
}
|
|
46419
46445
|
}
|
|
46420
46446
|
else {
|
|
@@ -46528,13 +46554,20 @@ function removeMatchingHeaders(regex, headers) {
|
|
|
46528
46554
|
delete headers[header];
|
|
46529
46555
|
}
|
|
46530
46556
|
}
|
|
46531
|
-
return lastValue
|
|
46557
|
+
return (lastValue === null || typeof lastValue === "undefined") ?
|
|
46558
|
+
undefined : String(lastValue).trim();
|
|
46532
46559
|
}
|
|
46533
46560
|
|
|
46534
46561
|
function createErrorType(code, defaultMessage) {
|
|
46535
|
-
function CustomError(
|
|
46562
|
+
function CustomError(cause) {
|
|
46536
46563
|
Error.captureStackTrace(this, this.constructor);
|
|
46537
|
-
|
|
46564
|
+
if (!cause) {
|
|
46565
|
+
this.message = defaultMessage;
|
|
46566
|
+
}
|
|
46567
|
+
else {
|
|
46568
|
+
this.message = defaultMessage + ": " + cause.message;
|
|
46569
|
+
this.cause = cause;
|
|
46570
|
+
}
|
|
46538
46571
|
}
|
|
46539
46572
|
CustomError.prototype = new Error();
|
|
46540
46573
|
CustomError.prototype.constructor = CustomError;
|
|
@@ -46551,6 +46584,11 @@ function abortRequest(request) {
|
|
|
46551
46584
|
request.abort();
|
|
46552
46585
|
}
|
|
46553
46586
|
|
|
46587
|
+
function isSubdomainOf(subdomain, domain) {
|
|
46588
|
+
const dot = subdomain.length - domain.length - 1;
|
|
46589
|
+
return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
|
|
46590
|
+
}
|
|
46591
|
+
|
|
46554
46592
|
// Exports
|
|
46555
46593
|
module.exports = wrap({ http: http, https: https });
|
|
46556
46594
|
module.exports.wrap = wrap;
|