From 83562aa0ec5d0e3fa5b6f89206f8eb84857db4b8 Mon Sep 17 00:00:00 2001 From: Coldwings Date: Thu, 6 Jun 2024 16:43:10 +0800 Subject: [PATCH] fix http server function test --- net/http/test/server_function_test.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/http/test/server_function_test.cpp b/net/http/test/server_function_test.cpp index 628f0ad9..a3940ff5 100644 --- a/net/http/test/server_function_test.cpp +++ b/net/http/test/server_function_test.cpp @@ -237,10 +237,12 @@ int chunked_handler_pt(void*, net::ISocketStream* sock) { return 0; } -int test_director(void*, Request& src, Request& dst) { - estring url; - url.appends(http_url_scheme, "127.0.0.1:19731", "/filename_not_important"); - dst.reset(src.verb(), url); +int test_director(void* src_, Request& src, Request& dst) { + auto source_server = (ISocketServer*)src_; + if (source_server) + dst.reset(src.verb(), to_url(source_server, "/filename_not_important")); + else + dst.reset(src.verb(), "http://localhost:0/filename_not_important"); dst.headers.insert("proxy_server_test", "just4test"); for (auto kv = src.headers.begin(); kv != src.headers.end(); kv++) { if (kv.first() != "Host") dst.headers.insert(kv.first(), kv.second(), 1); @@ -434,7 +436,8 @@ TEST(http_server, proxy_handler_failure) { DEFER(delete tcpserver); auto proxy_server = new_http_server(); DEFER(delete proxy_server); - auto proxy_handler = new_proxy_handler({nullptr, &test_director}, {nullptr, &test_modifier}, client_proxy); + auto proxy_handler = new_proxy_handler({nullptr, &test_director}, + {nullptr, &test_modifier}, client_proxy); proxy_server->add_handler(proxy_handler); tcpserver->set_handler(proxy_server->get_connection_handler()); tcpserver->start_loop();