mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00
LookupServer: Don't cache already-expired DNS answers
This commit is contained in:
parent
174583cda5
commit
d1721c761e
1 changed files with 9 additions and 4 deletions
|
@ -240,13 +240,18 @@ Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, u
|
|||
return {};
|
||||
}
|
||||
|
||||
Vector<String> responses;
|
||||
Vector<String, 8> responses;
|
||||
Vector<DNSAnswer, 8> cacheable_answers;
|
||||
for (auto& answer : response.answers()) {
|
||||
responses.append(answer.record_data());
|
||||
if (!answer.has_expired())
|
||||
cacheable_answers.append(answer);
|
||||
}
|
||||
|
||||
if (m_lookup_cache.size() >= 256)
|
||||
m_lookup_cache.remove(m_lookup_cache.begin());
|
||||
m_lookup_cache.set(hostname, { request.questions()[0], response.answers() });
|
||||
if (!cacheable_answers.is_empty()) {
|
||||
if (m_lookup_cache.size() >= 256)
|
||||
m_lookup_cache.remove(m_lookup_cache.begin());
|
||||
m_lookup_cache.set(hostname, { request.questions()[0], move(cacheable_answers) });
|
||||
}
|
||||
return responses;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue