mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1249450 part 1: Move GetSecureUpgradedURI from HttpBaseChannel to nsNetUtil. r=mcmanus
This commit is contained in:
parent
b5acf52487
commit
9b70d28e34
@ -1932,8 +1932,7 @@ NS_IsHSTSUpgradeRedirect(nsIChannel *aOldChannel,
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> upgradedURI;
|
||||
nsresult rv =
|
||||
HttpBaseChannel::GetSecureUpgradedURI(oldURI, getter_AddRefs(upgradedURI));
|
||||
nsresult rv = NS_GetSecureUpgradedURI(oldURI, getter_AddRefs(upgradedURI));
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
@ -2321,6 +2320,45 @@ NS_ShouldSecureUpgrade(nsIURI* aURI,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI)
|
||||
{
|
||||
nsCOMPtr<nsIURI> upgradedURI;
|
||||
|
||||
nsresult rv = aURI->Clone(getter_AddRefs(upgradedURI));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
// Change the scheme to HTTPS:
|
||||
upgradedURI->SetScheme(NS_LITERAL_CSTRING("https"));
|
||||
|
||||
// Change the default port to 443:
|
||||
nsCOMPtr<nsIStandardURL> upgradedStandardURL = do_QueryInterface(upgradedURI);
|
||||
if (upgradedStandardURL) {
|
||||
upgradedStandardURL->SetDefaultPort(443);
|
||||
} else {
|
||||
// If we don't have a nsStandardURL, fall back to using GetPort/SetPort.
|
||||
// XXXdholbert Is this function even called with a non-nsStandardURL arg,
|
||||
// in practice?
|
||||
int32_t oldPort = -1;
|
||||
rv = aURI->GetPort(&oldPort);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Keep any nonstandard ports so only the scheme is changed.
|
||||
// For example:
|
||||
// http://foo.com:80 -> https://foo.com:443
|
||||
// http://foo.com:81 -> https://foo.com:81
|
||||
|
||||
if (oldPort == 80 || oldPort == -1) {
|
||||
upgradedURI->SetPort(-1);
|
||||
} else {
|
||||
upgradedURI->SetPort(oldPort);
|
||||
}
|
||||
}
|
||||
|
||||
upgradedURI.forget(aUpgradedURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
|
@ -998,6 +998,12 @@ nsresult NS_ShouldSecureUpgrade(nsIURI* aURI,
|
||||
bool aAllowSTS,
|
||||
bool& aShouldUpgrade);
|
||||
|
||||
/**
|
||||
* Returns an https URI for channels that need to go through secure upgrades.
|
||||
*/
|
||||
nsresult NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI);
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
|
@ -3278,45 +3278,5 @@ HttpBaseChannel::SetBlockAuthPrompt(bool aValue)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
HttpBaseChannel::GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI)
|
||||
{
|
||||
nsCOMPtr<nsIURI> upgradedURI;
|
||||
|
||||
nsresult rv = aURI->Clone(getter_AddRefs(upgradedURI));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
// Change the scheme to HTTPS:
|
||||
upgradedURI->SetScheme(NS_LITERAL_CSTRING("https"));
|
||||
|
||||
// Change the default port to 443:
|
||||
nsCOMPtr<nsIStandardURL> upgradedStandardURL = do_QueryInterface(upgradedURI);
|
||||
if (upgradedStandardURL) {
|
||||
upgradedStandardURL->SetDefaultPort(443);
|
||||
} else {
|
||||
// If we don't have a nsStandardURL, fall back to using GetPort/SetPort.
|
||||
// XXXdholbert Is this function even called with a non-nsStandardURL arg,
|
||||
// in practice?
|
||||
int32_t oldPort = -1;
|
||||
rv = aURI->GetPort(&oldPort);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Keep any nonstandard ports so only the scheme is changed.
|
||||
// For example:
|
||||
// http://foo.com:80 -> https://foo.com:443
|
||||
// http://foo.com:81 -> https://foo.com:81
|
||||
|
||||
if (oldPort == 80 || oldPort == -1) {
|
||||
upgradedURI->SetPort(-1);
|
||||
} else {
|
||||
upgradedURI->SetPort(oldPort);
|
||||
}
|
||||
}
|
||||
|
||||
upgradedURI.forget(aUpgradedURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
@ -305,10 +305,6 @@ public: /* Necko internal use only... */
|
||||
// the new mUploadStream.
|
||||
void EnsureUploadStreamIsCloneableComplete(nsresult aStatus);
|
||||
|
||||
// Returns an https URI for channels that need to go through secure
|
||||
// upgrades.
|
||||
static nsresult GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI);
|
||||
|
||||
protected:
|
||||
nsCOMArray<nsISecurityConsoleMessage> mSecurityConsoleMessages;
|
||||
|
||||
|
@ -2663,7 +2663,7 @@ HttpChannelChild::ShouldInterceptURI(nsIURI* aURI,
|
||||
|
||||
nsCOMPtr<nsIURI> upgradedURI;
|
||||
if (aShouldUpgrade) {
|
||||
rv = GetSecureUpgradedURI(aURI, getter_AddRefs(upgradedURI));
|
||||
rv = NS_GetSecureUpgradedURI(aURI, getter_AddRefs(upgradedURI));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "nsHttpChannel.h"
|
||||
#include "HttpChannelChild.h"
|
||||
#include "nsHttpResponseHead.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "mozilla/ConsoleReportCollector.h"
|
||||
#include "mozilla/dom/ChannelInfo.h"
|
||||
#include "nsIChannelEventSink.h"
|
||||
@ -137,7 +138,7 @@ InterceptedChannelBase::SecureUpgradeChannelURI(nsIChannel* aChannel)
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
nsCOMPtr<nsIURI> upgradedURI;
|
||||
rv = HttpBaseChannel::GetSecureUpgradedURI(uri, getter_AddRefs(upgradedURI));
|
||||
rv = NS_GetSecureUpgradedURI(uri, getter_AddRefs(upgradedURI));
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
return upgradedURI.forget();
|
||||
@ -429,8 +430,8 @@ InterceptedChannelContent::FinishSynthesizedResponse(const nsACString& aFinalURL
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else if (mSecureUpgrade) {
|
||||
nsresult rv = HttpBaseChannel::GetSecureUpgradedURI(originalURI,
|
||||
getter_AddRefs(responseURI));
|
||||
nsresult rv = NS_GetSecureUpgradedURI(originalURI,
|
||||
getter_AddRefs(responseURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else {
|
||||
responseURI = originalURI;
|
||||
|
@ -1955,7 +1955,7 @@ nsHttpChannel::StartRedirectChannelToHttps()
|
||||
LOG(("nsHttpChannel::HandleAsyncRedirectChannelToHttps() [STS]\n"));
|
||||
|
||||
nsCOMPtr<nsIURI> upgradedURI;
|
||||
nsresult rv = GetSecureUpgradedURI(mURI, getter_AddRefs(upgradedURI));
|
||||
nsresult rv = NS_GetSecureUpgradedURI(mURI, getter_AddRefs(upgradedURI));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
return StartRedirectChannelToURI(upgradedURI,
|
||||
|
Loading…
Reference in New Issue
Block a user