From 30e38998be17c6d94b21a998a86e33e0b6c389c0 Mon Sep 17 00:00:00 2001 From: jackarain Date: Mon, 16 Oct 2023 22:47:54 +0800 Subject: [PATCH] Return authentication required page --- proxy/include/proxy/proxy_server.hpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/proxy/include/proxy/proxy_server.hpp b/proxy/include/proxy/proxy_server.hpp index 6a8f293de3..e53516e3db 100644 --- a/proxy/include/proxy/proxy_server.hpp +++ b/proxy/include/proxy/proxy_server.hpp @@ -1410,7 +1410,15 @@ namespace proxy { // http 代理认证. if (!http_proxy_authorization(pa)) - co_return false; + { + co_await net::async_write( + m_local_socket, + net::buffer(authentication_required_page()), + net::transfer_all(), + net_awaitable[ec]); + + co_return true; + } auto pos = target_view.find(':'); if (pos == std::string::npos) @@ -2582,6 +2590,19 @@ Connection: close return fake_content; } + inline const std::string& authentication_required_page() const + { + static std::string auth_required = +R"xxxxxx(HTTP/1.1 407 Proxy Authentication Required +Connection: close +Proxy-Authenticate: Basic realm="proxy" +Proxy-Connection: close +Content-Length: 0 + +)xxxxxx"; + return auth_required; + } + private: proxy_stream_type m_local_socket; proxy_stream_type m_remote_socket;