1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// HttpLog.h should generally be included first
#include "HttpLog.h"
#include "HTTPSRecordResolver.h"
#include "nsIDNSByTypeRecord.h"
#include "nsIDNSService.h"
#include "nsHttpConnectionInfo.h"
namespace mozilla {
namespace net {
NS_IMPL_ISUPPORTS(HTTPSRecordResolver, nsIDNSListener)
HTTPSRecordResolver::HTTPSRecordResolver(nsAHttpTransaction* aTransaction)
: mTransaction(aTransaction),
mConnInfo(aTransaction->ConnectionInfo()),
mCaps(aTransaction->Caps()) {}
HTTPSRecordResolver::~HTTPSRecordResolver() = default;
nsresult HTTPSRecordResolver::FetchHTTPSRRInternal(
nsIEventTarget* aTarget, nsICancelable** aDNSRequest) {
NS_ENSURE_ARG_POINTER(aTarget);
// Only fetch HTTPS RR for https.
if (!mConnInfo->FirstHopSSL()) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
if (!dns) {
return NS_ERROR_NOT_AVAILABLE;
}
uint32_t flags = nsIDNSService::GetFlagsFromTRRMode(mConnInfo->GetTRRMode());
if (mCaps & NS_HTTP_REFRESH_DNS) {
flags |= nsIDNSService::RESOLVE_BYPASS_CACHE;
}
return dns->AsyncResolveNative(
mConnInfo->GetOrigin(), nsIDNSService::RESOLVE_TYPE_HTTPSSVC, flags,
nullptr, this, aTarget, mConnInfo->GetOriginAttributes(), aDNSRequest);
}
NS_IMETHODIMP HTTPSRecordResolver::OnLookupComplete(nsICancelable* aRequest,
nsIDNSRecord* aRecord,
nsresult aStatus) {
nsCOMPtr<nsIDNSAddrRecord> addrRecord = do_QueryInterface(aRecord);
// This will be called again when receving the result of speculatively loading
// the addr records of the target name. In this case, just return NS_OK.
if (addrRecord) {
return NS_OK;
}
nsCOMPtr<nsIDNSHTTPSSVCRecord> record = do_QueryInterface(aRecord);
if (!record || NS_FAILED(aStatus)) {
return mTransaction->OnHTTPSRRAvailable(nullptr, nullptr);
}
nsCOMPtr<nsISVCBRecord> svcbRecord;
if (NS_FAILED(record->GetServiceModeRecord(mCaps & NS_HTTP_DISALLOW_SPDY,
mCaps & NS_HTTP_DISALLOW_HTTP3,
getter_AddRefs(svcbRecord)))) {
return mTransaction->OnHTTPSRRAvailable(record, nullptr);
}
return mTransaction->OnHTTPSRRAvailable(record, svcbRecord);
}
void HTTPSRecordResolver::PrefetchAddrRecord(const nsACString& aTargetName,
bool aRefreshDNS) {
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
if (!dns) {
return;
}
uint32_t flags = nsIDNSService::GetFlagsFromTRRMode(
mTransaction->ConnectionInfo()->GetTRRMode());
if (aRefreshDNS) {
flags |= nsIDNSService::RESOLVE_BYPASS_CACHE;
}
nsCOMPtr<nsICancelable> tmpOutstanding;
Unused << dns->AsyncResolveNative(
aTargetName, nsIDNSService::RESOLVE_TYPE_DEFAULT,
flags | nsIDNSService::RESOLVE_SPECULATE, nullptr, this,
GetCurrentEventTarget(),
mTransaction->ConnectionInfo()->GetOriginAttributes(),
getter_AddRefs(tmpOutstanding));
}
} // namespace net
} // namespace mozilla
|