From a91ebb7cd1fdfd6616ab55f03a6a65e3711d5bb9 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Wed, 28 Nov 2018 18:05:52 +0100 Subject: [PATCH] Bug 1510580 - Use nsIURIFixup in netwerk/protocol/http, r=valentin --- netwerk/protocol/http/HttpBaseChannel.cpp | 17 +++++++++++++---- netwerk/protocol/http/nsHttpChannel.cpp | 15 +++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index bea003e52b8f..229f469b78e9 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -68,6 +68,7 @@ #include "nsIXULRuntime.h" #include "nsICacheInfoChannel.h" #include "nsIDOMWindowUtils.h" +#include "nsIURIFixup.h" #include "nsHttpChannel.h" #include "nsRedirectHistoryEntry.h" #include "nsServerTiming.h" @@ -1905,10 +1906,18 @@ HttpBaseChannel::SetReferrerWithPolicy(nsIURI *referrer, // strip away any userpass; we don't want to be giving out passwords ;-) // This is required by Referrer Policy stripping algorithm. - rv = NS_MutateURI(clone) - .SetUserPass(EmptyCString()) - .Finalize(clone); - if (NS_FAILED(rv)) return rv; + nsCOMPtr urifixup = services::GetURIFixup(); + if (NS_WARN_IF(!urifixup)) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr exposableURI; + rv = urifixup->CreateExposableURI(clone, getter_AddRefs(exposableURI)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + clone = exposableURI; // 0: full URI // 1: scheme+host+port+path diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index fc9219cdd45d..8f88bf5c39a9 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -82,6 +82,7 @@ #include "nsIHttpChannelInternal.h" #include "nsIPrompt.h" #include "nsInputStreamPump.h" +#include "nsIURIFixup.h" #include "nsURLHelper.h" #include "nsISocketTransport.h" #include "nsIStreamConverterService.h" @@ -1113,11 +1114,17 @@ nsHttpChannel::SetupTransaction() if (NS_FAILED(rv)) return rv; if (!buf.IsEmpty() && ((strncmp(mSpec.get(), "http:", 5) == 0) || strncmp(mSpec.get(), "https:", 6) == 0)) { + nsCOMPtr urifixup = services::GetURIFixup(); + if (NS_WARN_IF(!urifixup)) { + return NS_ERROR_FAILURE; + } + nsCOMPtr tempURI; - rv = NS_MutateURI(mURI) - .SetUserPass(EmptyCString()) - .Finalize(tempURI); - if (NS_FAILED(rv)) return rv; + nsresult rv = urifixup->CreateExposableURI(mURI, getter_AddRefs(tempURI)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + rv = tempURI->GetAsciiSpec(path); if (NS_FAILED(rv)) return rv; requestURI = &path;