fixup patch and remove unused test feature

This commit is contained in:
Arvid Norberg
2026-02-15 11:21:28 +01:00
committed by Arvid Norberg
parent bf79a1a2b7
commit 9ecebca6e2
7 changed files with 19 additions and 17 deletions
+2 -2
View File
@@ -131,8 +131,8 @@ private:
// if we were given the original host (domain or IP), prefer using it (lets proxy resolve domains)
if (!m_host.empty())
{
std::string const remote_host = ::libtorrent::format_host_for_connect(
std::move(m_host),
std::string const remote_host = format_host_for_connect(
m_host,
m_remote_endpoint.port());
write_string("CONNECT " + remote_host + " HTTP/1.0\r\n", p);
+1 -1
View File
@@ -625,7 +625,7 @@ void test_connection_ssl_proxy(bool const with_hostname)
{
proxy_counter++;
TEST_EQUAL(method, "CONNECT");
// Host header is always sent to comply with RFC 9110 and RFC 9112 requirements.
// The send_host_in_connect setting controls the format:
// - true: Host header contains domain:port format
+10 -3
View File
@@ -404,17 +404,24 @@ namespace libtorrent {
// Already bracketed IPv6 literal
if (!host.empty() && host.front() == '[' && host.back() == ']')
{
return host + ":" + to_string(port).data();
host += ":";
host += to_string(port).data();
return host;
}
// Contains colons (unbracketed IPv6) - need to bracket
if (host.find(':') != string_view::npos)
{
return "[" + host + "]:" + to_string(port).data();
host = "[" + host;
host += "]:";
host += to_string(port).data();
return host;
}
// Regular hostname or IPv4
return host + ":" + to_string(port).data();
host += ":";
host += to_string(port).data();
return host;
}
#if TORRENT_USE_I2P
+2 -6
View File
@@ -152,7 +152,6 @@ class Handler(http.server.BaseHTTPRequestHandler):
close_connection = True
timeout = 30
basic_auth = None
require_host_header = True # Always require Host header in CONNECT requests for proper HTTP compliance
def authorize(self):
"""Returns whether the request is authorized."""
@@ -209,8 +208,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
# Check if Host header is present (useful for debugging libtorrent CONNECT requests)
host_header = self.headers.get("Host")
if host_header:
self.log_message("CONNECT request: target=%s:%s, Host header=%s",
host, port, host_header)
self.log_message("CONNECT request: target=%s:%s, Host header=%s",
host, port, host_header)
# Check if Host header matches CONNECT target
if host_header == f"{host}:{port}":
self.log_message("Host header matches CONNECT target")
@@ -536,8 +535,6 @@ class Main:
self.parser.add_argument("--basic-auth")
self.parser.add_argument("--timeout", type=int, default=30)
self.parser.add_argument("--bind-host", default="localhost")
self.parser.add_argument("--require-host-header", action="store_true",
help="Require Host header in CONNECT requests (enabled by default for HTTP/1.1 compliance)")
self.args = None
self.server = None
@@ -556,7 +553,6 @@ class Main:
Handler.basic_auth = None
Handler.timeout = self.args.timeout
Handler.require_host_header = self.args.require_host_header
self.server = _ThreadingHTTPServer(self.address, Handler)
self.server.serve_forever()
+2 -3
View File
@@ -736,7 +736,7 @@ int find_available_port()
} // anonymous namespace
// returns a port on success and -1 on failure
int start_proxy(int proxy_type, bool const require_host)
int start_proxy(int proxy_type)
{
using namespace lt;
@@ -751,7 +751,6 @@ int start_proxy(int proxy_type, bool const require_host)
char const* type = "";
char const* auth = "";
char const* cmd = "";
char const* host = require_host ? " --require-host-header" : "";
switch (proxy_type)
{
@@ -783,7 +782,7 @@ int start_proxy(int proxy_type, bool const require_host)
for (auto const& python_exe : python_exes)
{
char buf[1024];
std::snprintf(buf, sizeof(buf), "%s %s --port %d%s%s", python_exe.c_str(), cmd, port, auth, host);
std::snprintf(buf, sizeof(buf), "%s %s --port %d%s", python_exe.c_str(), cmd, port, auth);
std::printf("%s starting proxy on port %d (%s %s)...\n", time_now_string().c_str(), port, type, auth);
std::printf("%s\n", buf);
+1 -1
View File
@@ -116,7 +116,7 @@ EXPORT int start_web_server(bool ssl = false, bool chunked = false
, bool keepalive = true, int min_interval = 30);
EXPORT void stop_web_server();
EXPORT int start_proxy(int type, bool require_host = false);
EXPORT int start_proxy(int type);
EXPORT void stop_proxy(int port);
EXPORT void stop_all_proxies();
+1 -1
View File
@@ -183,7 +183,7 @@ void run_suite(std::string const& protocol
ps.type = proxy_type;
if (ps.type != settings_pack::none)
ps.port = aux::numeric_cast<std::uint16_t>(start_proxy(ps.type, flags & flag_send_host));
ps.port = aux::numeric_cast<std::uint16_t>(start_proxy(ps.type));
ps.send_host_in_connect = flags & flag_send_host;
using err = boost::optional<error_code>;