ladybird/Libraries/LibWeb/Loader/ProxyMappings.cpp
Andreas Kling 164ed80244 Meta: Enable exit-time destructor warnings for libraries
Enable -Wexit-time-destructors for all in-tree library targets and
update process-lifetime library statics so they no longer register
exit-time destructors. Long-lived caches, lookup tables, singleton
registries, and generated constants now use NeverDestroyed or leaked
references where the data is intended to live until process exit.

Update LibWeb, LibLine, and the binding generators so regenerated
sources follow the same rule instead of reintroducing destructed
statics.
2026-06-04 19:20:49 +02:00

44 lines
1.3 KiB
C++

/*
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ProxyMappings.h"
#include <LibURL/Parser.h>
Web::ProxyMappings& Web::ProxyMappings::the()
{
static ProxyMappings& instance = *new ProxyMappings;
return instance;
}
Core::ProxyData Web::ProxyMappings::proxy_for_url(URL::URL const& url) const
{
auto url_string = url.to_byte_string();
for (auto& it : m_mappings) {
if (url_string.matches(it.key)) {
auto maybe_url = URL::Parser::basic_parse(m_proxies[it.value]);
if (!maybe_url.has_value()) {
dbgln("Failed to parse proxy URL: {}", m_proxies[it.value]);
continue;
}
auto result = Core::ProxyData::parse_url(maybe_url.value());
if (result.is_error()) {
dbgln("Failed to parse proxy URL: {}", m_proxies[it.value]);
continue;
}
return result.release_value();
}
}
return {};
}
void Web::ProxyMappings::set_mappings(Vector<ByteString> proxies, OrderedHashMap<ByteString, size_t> mappings)
{
m_proxies = move(proxies);
m_mappings = move(mappings);
dbgln("Proxy mappings updated: proxies: {}", m_proxies);
}