
This URL library ends up being a relatively fundamental base library of the system, as LibCore depends on LibURL. This change has two main benefits: * Moving AK back more towards being an agnostic library that can be used between the kernel and userspace. URL has never really fit that description - and is not used in the kernel. * URL _should_ depend on LibUnicode, as it needs punnycode support. However, it's not really possible to do this inside of AK as it can't depend on any external library. This change brings us a little closer to being able to do that, but unfortunately we aren't there quite yet, as the code generators depend on LibCore.
38 lines
1,001 B
C++
38 lines
1,001 B
C++
/*
|
|
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "ProxyMappings.h"
|
|
|
|
Web::ProxyMappings& Web::ProxyMappings::the()
|
|
{
|
|
static ProxyMappings instance {};
|
|
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 result = Core::ProxyData::parse_url(m_proxies[it.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);
|
|
}
|