mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
Enhance DNS prefetching by resolving URIs against the document base URI
This commit is contained in:
parent
ad5d1d60e5
commit
b913fa62d9
1 changed files with 12 additions and 9 deletions
|
|
@ -923,15 +923,15 @@ nsContentSink::PrefetchDNS(const nsAString &aHref)
|
|||
{
|
||||
nsAutoString hostname;
|
||||
|
||||
if (StringBeginsWith(aHref, NS_LITERAL_STRING("//"))) {
|
||||
hostname = Substring(aHref, 2);
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), aHref);
|
||||
if (!uri) {
|
||||
return;
|
||||
}
|
||||
// Resolve against the document base URI so relative and scheme-relative
|
||||
// Link header values can still extract a hostname for speculation.
|
||||
const nsACString& charset = mDocument->GetDocumentCharacterSet();
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), aHref,
|
||||
charset.IsEmpty() ? nullptr : PromiseFlatCString(charset).get(),
|
||||
mDocument->GetDocBaseURI());
|
||||
|
||||
if (uri) {
|
||||
nsresult rv;
|
||||
bool isLocalResource = false;
|
||||
rv = NS_URIChainHasFlags(uri, nsIProtocolHandler::URI_IS_LOCAL_RESOURCE,
|
||||
|
|
@ -941,6 +941,9 @@ nsContentSink::PrefetchDNS(const nsAString &aHref)
|
|||
uri->GetHost(host);
|
||||
CopyUTF8toUTF16(host, hostname);
|
||||
}
|
||||
} else if (aHref.FindChar('/') == kNotFound && aHref.FindChar(':') == kNotFound) {
|
||||
// Support a bare hostname token in Link headers.
|
||||
hostname = aHref;
|
||||
}
|
||||
|
||||
if (!hostname.IsEmpty() && nsHTMLDNSPrefetch::IsAllowed(mDocument)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue