blob: 687ea485fea534580f94a5c0cab57c2c987cb674 (
plain)
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
|
/*
* 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(AK::URL const& url) const
{
auto url_string = url.to_deprecated_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<DeprecatedString> proxies, OrderedHashMap<DeprecatedString, size_t> mappings)
{
m_proxies = move(proxies);
m_mappings = move(mappings);
dbgln("Proxy mappings updated: proxies: {}", m_proxies);
}
|