Skip to content

Commit

Permalink
Return authentication required page
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed Oct 16, 2023
1 parent 9d822a4 commit 30e3899
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion proxy/include/proxy/proxy_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 30e3899

Please sign in to comment.