New SHARED module built on Boost.Beast/Asio + OpenSSL (all generic, no application coupling): - Void::Net::Url — RFC 3986 parse into scheme/host/port/path/query/target (Boost.URL), with scheme-default ports and TLS detection. - Void::Net::HttpClient — synchronous GET/POST/send with TLS (SNI), configurable User-Agent and TLS verification, request/response types. - Proxy support: HTTP CONNECT tunnelling for TLS targets, plain-HTTP forwarding, and a full SOCKS5 handshake (auth, IPv4/IPv6/domain). - Reuses Void::Encoding::Base64 for proxy auth. Build wiring: Dependencies.cmake resolves Boost (headers + url) and OpenSSL + Threads via find_package (system Boost/OpenSSL). Tests cover URL parsing and live localhost HTTP GET/POST round-trips (full suite 1136 pass). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
#include <Void/Net/Url.hpp>
|
|
|
|
#include <boost/url/parse.hpp>
|
|
#include <boost/url/url_view.hpp>
|
|
|
|
namespace Void::Net
|
|
{
|
|
|
|
std::optional<Url> Url::parse(std::string_view url)
|
|
{
|
|
namespace urls = boost::urls;
|
|
auto parsed = urls::parse_uri(url);
|
|
if (!parsed) {
|
|
// Some callers pass scheme-relative or relative refs; try the
|
|
// looser reference parser before giving up.
|
|
parsed = urls::parse_uri_reference(url);
|
|
if (!parsed) {
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
const auto& uri = *parsed;
|
|
|
|
Url out;
|
|
out.scheme = std::string{uri.scheme()};
|
|
out.host = std::string{uri.host()};
|
|
out.is_tls = (out.scheme == "https" || out.scheme == "wss");
|
|
|
|
if (uri.has_port()) {
|
|
out.port = std::string{uri.port()};
|
|
} else {
|
|
out.port = out.is_tls ? "443" : "80";
|
|
}
|
|
|
|
out.path = std::string{uri.encoded_path()};
|
|
if (out.path.empty()) {
|
|
out.path = "/";
|
|
}
|
|
out.target = out.path;
|
|
if (uri.has_query()) {
|
|
out.query = std::string{uri.encoded_query()};
|
|
out.target += "?";
|
|
out.target += out.query;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
} // namespace Void::Net
|