// if there's no location to redirect to, we won't
break;
}
letparsedRedirectUrl=url.parse(redirectUrl);
if (parsedUrl.protocol=='https:'&&parsedUrl.protocol!=parsedRedirectUrl.protocol&&!this._allowRedirectDowngrade){
thrownewError("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.");
if (parsedUrl.protocol=='https:'&&
parsedUrl.protocol!=parsedRedirectUrl.protocol&&
!this._allowRedirectDowngrade){
thrownewError('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.');
}
// we need to finish reading the response before reassigning response
// which will leak the open socket.
awaitresponse.readBody();
// strip authorization header if redirected to a different hostname
if (parsedRedirectUrl.hostname!==parsedUrl.hostname){
for (letheaderinheaders){
// header names are case insensitive
if (header.toLowerCase()==='authorization'){
deleteheaders[header];
}
}
}
// let's make the request with the new redirectUrl
// if there's no location to redirect to, we won't
break;
}
letparsedRedirectUrl=url.parse(redirectUrl);
if (parsedUrl.protocol=='https:'&&parsedUrl.protocol!=parsedRedirectUrl.protocol&&!this._allowRedirectDowngrade){
thrownewError("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.");
if (parsedUrl.protocol=='https:'&&
parsedUrl.protocol!=parsedRedirectUrl.protocol&&
!this._allowRedirectDowngrade){
thrownewError('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.');
}
// we need to finish reading the response before reassigning response
// which will leak the open socket.
awaitresponse.readBody();
// strip authorization header if redirected to a different hostname
if (parsedRedirectUrl.hostname!==parsedUrl.hostname){
for (letheaderinheaders){
// header names are case insensitive
if (header.toLowerCase()==='authorization'){
deleteheaders[header];
}
}
}
// let's make the request with the new redirectUrl