mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +00:00
pro: Accept an optional proxy to tunnel the download through
For now, this only accepts the format `socks5://ip:port` (i.e. the hostname has to be an ipv4, and the port must be present).
This commit is contained in:
parent
45867435c4
commit
f9fc28931f
2 changed files with 32 additions and 2 deletions
|
@ -7,7 +7,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/IPv4Address.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
|
||||
namespace Core {
|
||||
|
@ -22,6 +24,30 @@ struct ProxyData {
|
|||
int port { 0 };
|
||||
|
||||
bool operator==(ProxyData const& other) const = default;
|
||||
|
||||
static ErrorOr<ProxyData> parse_url(URL const& url)
|
||||
{
|
||||
if (!url.is_valid())
|
||||
return Error::from_string_literal("Invalid proxy URL");
|
||||
|
||||
ProxyData proxy_data;
|
||||
if (url.scheme() != "socks5")
|
||||
return Error::from_string_literal("Unsupported proxy type");
|
||||
|
||||
proxy_data.type = ProxyData::Type::SOCKS5;
|
||||
|
||||
auto host_ipv4 = IPv4Address::from_string(url.host());
|
||||
if (!host_ipv4.has_value())
|
||||
return Error::from_string_literal("Invalid proxy host, must be an IPv4 address");
|
||||
proxy_data.host_ipv4 = host_ipv4->to_u32();
|
||||
|
||||
auto port = url.port();
|
||||
if (!port.has_value())
|
||||
return Error::from_string_literal("Invalid proxy, must have a port");
|
||||
proxy_data.port = *port;
|
||||
|
||||
return proxy_data;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue