From f4cda9e92edccc48093eb47e86c99900cea0d5de Mon Sep 17 00:00:00 2001 From: Dragana Damjanovic Date: Thu, 29 Nov 2018 10:15:13 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- netwerk/protocol/http/AlternateServices.cpp | 12 +++++++++++- netwerk/protocol/http/nsHttpChannel.cpp | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/netwerk/protocol/http/AlternateServices.cpp b/netwerk/protocol/http/AlternateServices.cpp index 5d85cac8d165..b561cb2209d2 100644 --- a/netwerk/protocol/http/AlternateServices.cpp +++ b/netwerk/protocol/http/AlternateServices.cpp @@ -942,7 +942,17 @@ AltSvcCache::UpdateAltServiceMapping(AltSvcMapping *map, nsProxyInfo *pi, } } 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()); diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 8f88bf5c39a9..92e42c0e2bb4 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -2169,7 +2169,7 @@ nsHttpChannel::ProcessAltService() nsAutoCString originHost; int32_t originPort = 80; mURI->GetPort(&originPort); - if (NS_FAILED(mURI->GetHost(originHost))) { + if (NS_FAILED(mURI->GetAsciiHost(originHost))) { return; }