mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
Browser+LibWeb+WebContent: Implement per-URL-pattern proxies
...at least for SOCKS5.
This commit is contained in:
parent
f9fc28931f
commit
a42e03b01a
15 changed files with 155 additions and 6 deletions
41
Userland/Libraries/LibWeb/Loader/ProxyMappings.cpp
Normal file
41
Userland/Libraries/LibWeb/Loader/ProxyMappings.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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_string();
|
||||
for (auto& it : m_mappings) {
|
||||
dbgln("Checking {} against {}...", url, it.key);
|
||||
if (url_string.matches(it.key)) {
|
||||
dbgln("Matched!");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
dbgln("No luck!");
|
||||
return {};
|
||||
}
|
||||
|
||||
void Web::ProxyMappings::set_mappings(Vector<String> proxies, OrderedHashMap<String, size_t> mappings)
|
||||
{
|
||||
m_proxies = move(proxies);
|
||||
m_mappings = move(mappings);
|
||||
|
||||
dbgln("Proxy mappings updated: proxies: {}", m_proxies);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue