diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 35c2582d4b58..2e5910d6597c 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -2204,12 +2204,8 @@ nsresult nsHttpHandler::SpeculativeConnectInternal( originAttributes = std::move(aOriginAttributes.ref()); } else if (aPrincipal) { originAttributes = aPrincipal->OriginAttributesRef(); - StoragePrincipalHelper::UpdateOriginAttributesForNetworkState( - aURI, originAttributes); } else if (loadContext) { loadContext->GetOriginAttributes(originAttributes); - StoragePrincipalHelper::UpdateOriginAttributesForNetworkState( - aURI, originAttributes); } nsCOMPtr clone; @@ -2222,6 +2218,15 @@ nsresult nsHttpHandler::SpeculativeConnectInternal( } } + if (!aOriginAttributes) { + // We must update the originAttributes with the network state first party + // domain **after** we upgrade aURI to https. + // Otherwise the speculative connection will be keyed by a http URL + // and end up not being used. + StoragePrincipalHelper::UpdateOriginAttributesForNetworkState( + aURI, originAttributes); + } + nsAutoCString scheme; nsresult rv = aURI->GetScheme(scheme); if (NS_FAILED(rv)) return rv;