aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/servers/httpasio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenhttp/servers/httpasio.cpp')
-rw-r--r--src/zenhttp/servers/httpasio.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/zenhttp/servers/httpasio.cpp b/src/zenhttp/servers/httpasio.cpp
index a2cae8762..6cda84875 100644
--- a/src/zenhttp/servers/httpasio.cpp
+++ b/src/zenhttp/servers/httpasio.cpp
@@ -1275,7 +1275,9 @@ HttpServerConnectionT<SocketType>::HandleRequest()
asio::buffer(ResponseStr->data(), ResponseStr->size()),
asio::bind_executor(
m_Strand,
- [Conn = AsSharedPtr(), WsHandler, OwnedResponse = ResponseStr](const asio::error_code& Ec, std::size_t) {
+ [Conn = AsSharedPtr(), WsHandler, OwnedResponse = ResponseStr, PrefixLen = Service->UriPrefixLength()](
+ const asio::error_code& Ec,
+ std::size_t) {
if (Ec)
{
ZEN_WARN("WebSocket 101 send failed: {}", Ec.message());
@@ -1287,7 +1289,9 @@ HttpServerConnectionT<SocketType>::HandleRequest()
Ref<WsConnType> WsConn(new WsConnType(std::move(Conn->m_Socket), *WsHandler, Conn->m_Server.m_HttpServer));
Ref<WebSocketConnection> WsConnRef(WsConn.Get());
- WsHandler->OnWebSocketOpen(std::move(WsConnRef));
+ std::string_view FullUrl = Conn->m_RequestData.Url();
+ std::string_view RelativeUri = FullUrl.substr(std::min(PrefixLen, static_cast<int>(FullUrl.size())));
+ WsHandler->OnWebSocketOpen(std::move(WsConnRef), RelativeUri);
WsConn->Start();
}));
@@ -1330,14 +1334,36 @@ HttpServerConnectionT<SocketType>::HandleRequest()
{
auto RemoteEndpoint = m_Socket->remote_endpoint();
IsLocalConnection = m_Socket->local_endpoint().address() == RemoteEndpoint.address();
- RemoteAddress = RemoteEndpoint.address().to_string();
+ auto Addr = RemoteEndpoint.address();
+ RemoteAddress = Addr.to_string();
+ if (Addr.is_v4())
+ {
+ auto Bytes = Addr.to_v4().to_bytes();
+ m_Server.m_HttpServer->MarkClientAddress(Bytes.data(), Bytes.size());
+ }
+ else
+ {
+ auto Bytes = Addr.to_v6().to_bytes();
+ m_Server.m_HttpServer->MarkClientAddress(Bytes.data(), Bytes.size());
+ }
}
#if ZEN_USE_OPENSSL
else if constexpr (std::is_same_v<SocketType, SslSocket>)
{
auto RemoteEndpoint = m_Socket->lowest_layer().remote_endpoint();
IsLocalConnection = m_Socket->lowest_layer().local_endpoint().address() == RemoteEndpoint.address();
- RemoteAddress = RemoteEndpoint.address().to_string();
+ auto Addr = RemoteEndpoint.address();
+ RemoteAddress = Addr.to_string();
+ if (Addr.is_v4())
+ {
+ auto Bytes = Addr.to_v4().to_bytes();
+ m_Server.m_HttpServer->MarkClientAddress(Bytes.data(), Bytes.size());
+ }
+ else
+ {
+ auto Bytes = Addr.to_v6().to_bytes();
+ m_Server.m_HttpServer->MarkClientAddress(Bytes.data(), Bytes.size());
+ }
}
#endif
else
@@ -1345,6 +1371,8 @@ HttpServerConnectionT<SocketType>::HandleRequest()
RemoteAddress = "unix";
}
+ m_Server.m_HttpServer->MarkSessionId(m_RequestData.SessionId());
+
HttpAsioServerRequest Request(m_RequestData,
*Service,
m_RequestData.Body(),