Bug 1510580 - Use nsIURIFixup in netwerk/protocol/http, r=valentin
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 28 Nov 2018 18:05:52 +0100
changeset 448505 3241939e39a97dbda57305bf96a4ea1d72fcd5df
parent 448504 cfb51d413370736adc5200b42598564d7ac2d59b
child 448506 d43ea215cceebe13bf68fde77dc75fc91c94d1dc
push id110201
push useramarchesini@mozilla.com
push dateWed, 28 Nov 2018 17:07:35 +0000
treeherdermozilla-inbound@d43ea215ccee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1510580
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1510580 - Use nsIURIFixup in netwerk/protocol/http, r=valentin
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -63,16 +63,17 @@
 #include "mozilla/Move.h"
 #include "mozilla/net/PartiallySeekableInputStream.h"
 #include "mozilla/InputStreamLengthHelper.h"
 #include "nsIHttpHeaderVisitor.h"
 #include "nsIMIMEInputStream.h"
 #include "nsIXULRuntime.h"
 #include "nsICacheInfoChannel.h"
 #include "nsIDOMWindowUtils.h"
+#include "nsIURIFixup.h"
 #include "nsHttpChannel.h"
 #include "nsRedirectHistoryEntry.h"
 #include "nsServerTiming.h"
 
 #include <algorithm>
 #include "HttpBaseChannel.h"
 
 namespace mozilla {
@@ -1900,20 +1901,28 @@ HttpBaseChannel::SetReferrerWithPolicy(n
     rv = NS_GetURIWithoutRef(mURI, getter_AddRefs(mURIclone));
     if (NS_FAILED(rv)) return rv;
     clone = mURIclone;
     currentHost = referrerHost;
   }
 
   // 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<nsIURIFixup> urifixup = services::GetURIFixup();
+  if (NS_WARN_IF(!urifixup)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsIURI> 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
   // 2: scheme+host+port
   int userReferrerTrimmingPolicy = gHttpHandler->ReferrerTrimmingPolicy();
   int userReferrerXOriginTrimmingPolicy =
     gHttpHandler->ReferrerXOriginTrimmingPolicy();
 
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -77,16 +77,17 @@
 #include "netCore.h"
 #include "nsHttpTransaction.h"
 #include "nsICacheEntryDescriptor.h"
 #include "nsICancelable.h"
 #include "nsIHttpChannelAuthProvider.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIPrompt.h"
 #include "nsInputStreamPump.h"
+#include "nsIURIFixup.h"
 #include "nsURLHelper.h"
 #include "nsISocketTransport.h"
 #include "nsIStreamConverterService.h"
 #include "nsISiteSecurityService.h"
 #include "nsString.h"
 #include "nsCRT.h"
 #include "CacheObserver.h"
 #include "mozilla/dom/PerformanceStorage.h"
@@ -1108,21 +1109,27 @@ nsHttpChannel::SetupTransaction()
         mRequestHead.SetPath(*requestURI);
 
         // RequestURI should be the absolute uri H1 proxy syntax "http://foo/index.html"
         // so we will overwrite the relative version in requestURI
         rv = mURI->GetUserPass(buf);
         if (NS_FAILED(rv)) return rv;
         if (!buf.IsEmpty() && ((strncmp(mSpec.get(), "http:", 5) == 0) ||
                                 strncmp(mSpec.get(), "https:", 6) == 0)) {
+            nsCOMPtr<nsIURIFixup> urifixup = services::GetURIFixup();
+            if (NS_WARN_IF(!urifixup)) {
+              return NS_ERROR_FAILURE;
+            }
+
             nsCOMPtr<nsIURI> 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;
         } else {
             requestURI = &mSpec;
         }
 
         // trim off the #ref portion if any...