Bug 1502462 - The altSrv checker does not build a uri correctly if origin is ipv6 address. r=valentin
authorDragana Damjanovic <dd.mozilla@gmail.com>
Thu, 29 Nov 2018 10:15:13 +0000
changeset 505145 eff4ffb1d280a3dc97b330d876d72542ee2ee32d
parent 505144 952e4606a7c9334cc0213396e7b63faa414a20f1
child 505146 eb07312cfbe868780ebed84fc83e5a5470e81fb4
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1502462
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 1502462 - The altSrv checker does not build a uri correctly if origin is ipv6 address. r=valentin AltSvcMapping::ProcessHeader should use GetAsciiHost instead of GetHost. Differential Revision: https://phabricator.services.mozilla.com/D13066
netwerk/protocol/http/AlternateServices.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/protocol/http/AlternateServices.cpp
+++ b/netwerk/protocol/http/AlternateServices.cpp
@@ -937,17 +937,27 @@ AltSvcCache::UpdateAltServiceMapping(Alt
     nsresult rv = gHttpHandler->ConnMgr()->SpeculativeConnect(ci, callbacks, caps, nullTransaction);
     if (NS_FAILED(rv)) {
       LOG(("AltSvcCache::UpdateAltServiceMapping %p "
            "speculative connect failed with code %08x\n", this,
            static_cast<uint32_t>(rv)));
     }
   } else {
     // for http:// resources we fetch .well-known too
-    nsAutoCString origin (NS_LITERAL_CSTRING("http://") + map->OriginHost());
+    nsAutoCString origin (NS_LITERAL_CSTRING("http://"));
+
+    // Check whether origin is an ipv6 address. In that case we need to add
+    // '[]'.
+    if (map->OriginHost().FindChar(':') != kNotFound) {
+      origin.Append('[');
+      origin.Append(map->OriginHost());
+      origin.Append(']');
+    } else {
+      origin.Append(map->OriginHost());
+    }
     if (map->OriginPort() != NS_HTTP_DEFAULT_PORT) {
       origin.Append(':');
       origin.AppendInt(map->OriginPort());
     }
 
     nsCOMPtr<nsIURI> wellKnown;
     nsAutoCString uri(origin);
     uri.AppendLiteral("/.well-known/http-opportunistic");
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -2164,17 +2164,17 @@ nsHttpChannel::ProcessAltService()
     if (!nsHttp::IsReasonableHeaderValue(altSvc)) {
         LOG(("Alt-Svc Response Header seems unreasonable - skipping\n"));
         return;
     }
 
     nsAutoCString originHost;
     int32_t originPort = 80;
     mURI->GetPort(&originPort);
-    if (NS_FAILED(mURI->GetHost(originHost))) {
+    if (NS_FAILED(mURI->GetAsciiHost(originHost))) {
         return;
     }
 
     nsCOMPtr<nsIInterfaceRequestor> callbacks;
     nsCOMPtr<nsProxyInfo> proxyInfo;
     NS_NewNotificationCallbacksAggregation(mCallbacks, mLoadGroup,
                                            getter_AddRefs(callbacks));
     if (mProxyInfo) {