mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-26 12:17:52 +00:00
LibDNS+RequestServer: Don't construct Vectors to validate DNS response
Instead of filling vectors and returning them just to invoke `.is_empty()`, forward the calls to the underlying vectors directly.
This commit is contained in:
parent
62d85dd90a
commit
41cf150a5b
Notes:
github-actions[bot]
2025-08-13 14:31:42 +00:00
Author: https://github.com/gmta
Commit: 41cf150a5b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5841
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 11 additions and 4 deletions
|
@ -78,6 +78,11 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
bool has_cached_addresses() const
|
||||
{
|
||||
return has_record_of_type(Messages::ResourceType::A) || has_record_of_type(Messages::ResourceType::AAAA);
|
||||
}
|
||||
|
||||
void check_expiration()
|
||||
{
|
||||
if (!m_valid)
|
||||
|
@ -110,8 +115,9 @@ public:
|
|||
Vector<Messages::ResourceRecord> records() const
|
||||
{
|
||||
Vector<Messages::ResourceRecord> result;
|
||||
result.ensure_capacity(m_cached_records.size());
|
||||
for (auto& re : m_cached_records)
|
||||
result.append(re.record);
|
||||
result.unchecked_append(re.record);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -164,6 +170,7 @@ public:
|
|||
|
||||
bool can_be_removed() const { return !m_valid && m_request_done; }
|
||||
bool is_done() const { return m_request_done; }
|
||||
bool is_empty() const { return m_cached_records.is_empty(); }
|
||||
void set_dnssec_validated(bool validated) { m_dnssec_validated = validated; }
|
||||
bool is_dnssec_validated() const { return m_dnssec_validated; }
|
||||
void set_being_dnssec_validated(bool validated) { m_being_dnssec_validated = validated; }
|
||||
|
|
|
@ -53,7 +53,7 @@ static NonnullRefPtr<Resolver> default_resolver()
|
|||
return Error::from_string_literal("No DNS server configured");
|
||||
|
||||
auto resolved = TRY(default_resolver()->dns.lookup(*g_dns_info.server_hostname)->await());
|
||||
if (resolved->cached_addresses().is_empty())
|
||||
if (!resolved->has_cached_addresses())
|
||||
return Error::from_string_literal("Failed to resolve DNS server hostname");
|
||||
auto address = resolved->cached_addresses().first().visit([](auto& addr) -> Core::SocketAddress { return { addr, g_dns_info.port }; });
|
||||
g_dns_info.server_address = address;
|
||||
|
@ -469,7 +469,7 @@ void ConnectionFromClient::start_request(i32 request_id, ByteString method, URL:
|
|||
async_request_finished(request_id, 0, {}, Requests::NetworkError::UnableToResolveHost);
|
||||
})
|
||||
.when_resolved([this, request_id, host = move(host), url = move(url), method = move(method), request_body = move(request_body), request_headers = move(request_headers), proxy_data](auto const& dns_result) mutable {
|
||||
if (dns_result->records().is_empty() || dns_result->cached_addresses().is_empty()) {
|
||||
if (dns_result->is_empty() || !dns_result->has_cached_addresses()) {
|
||||
dbgln("StartRequest: DNS lookup failed for '{}'", host);
|
||||
// FIXME: Implement timing info for DNS lookup failure.
|
||||
async_request_finished(request_id, 0, {}, Requests::NetworkError::UnableToResolveHost);
|
||||
|
@ -821,7 +821,7 @@ void ConnectionFromClient::websocket_connect(i64 websocket_id, URL::URL url, Byt
|
|||
async_websocket_errored(websocket_id, static_cast<i32>(Requests::WebSocket::Error::CouldNotEstablishConnection));
|
||||
})
|
||||
.when_resolved([this, websocket_id, host = move(host), url = move(url), origin = move(origin), protocols = move(protocols), extensions = move(extensions), additional_request_headers = move(additional_request_headers)](auto const& dns_result) mutable {
|
||||
if (dns_result->records().is_empty() || dns_result->cached_addresses().is_empty()) {
|
||||
if (dns_result->is_empty() || !dns_result->has_cached_addresses()) {
|
||||
dbgln("WebSocketConnect: DNS lookup failed for '{}'", host);
|
||||
async_websocket_errored(websocket_id, static_cast<i32>(Requests::WebSocket::Error::CouldNotEstablishConnection));
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue