mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
8751be09f9
In order to follow spec text to achieve this, we need to change the underlying representation of a host in AK::URL to deserialized format. Before this, we were parsing the host and then immediately serializing it again. Making that change resulted in a whole bunch of fallout. After this change, callers can access the serialized data through this concept-host-serializer. The functional end result of this change is that IPv6 hosts are now correctly serialized to be surrounded with '[' and ']'.
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/IPv4Address.h>
|
|
#include <AK/Types.h>
|
|
#include <AK/URL.h>
|
|
#include <LibIPC/Forward.h>
|
|
|
|
namespace Core {
|
|
// FIXME: Username/password support.
|
|
struct ProxyData {
|
|
enum Type {
|
|
Direct,
|
|
SOCKS5,
|
|
} type { Type::Direct };
|
|
|
|
u32 host_ipv4 { 0 };
|
|
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;
|
|
|
|
if (!url.host().has<URL::IPv4Address>())
|
|
return Error::from_string_literal("Invalid proxy host, must be an IPv4 address");
|
|
proxy_data.host_ipv4 = url.host().get<URL::IPv4Address>();
|
|
|
|
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;
|
|
}
|
|
};
|
|
}
|
|
|
|
namespace IPC {
|
|
|
|
template<>
|
|
ErrorOr<void> encode(Encoder&, Core::ProxyData const&);
|
|
|
|
template<>
|
|
ErrorOr<Core::ProxyData> decode(Decoder&);
|
|
|
|
}
|