@@ -59,6 +59,14 @@ void WebSocketServer::OnMessage(const std::string& message, std::shared_ptr<ix::
5959 if (!pWebSocketClient->m_websocket_handle ) return ;
6060 pWebSocketClient->m_keepConnecting = true ;
6161
62+ {
63+ std::lock_guard<std::mutex> lock (m_headersMutex);
64+ auto it = m_connectionHeaders.find (connectionState->getId ());
65+ if (it != m_connectionHeaders.end ()) {
66+ pWebSocketClient->m_headers = it->second ;
67+ }
68+ }
69+
6270 std::string remoteAddress = connectionState->getRemoteIp () + " :" + std::to_string (connectionState->getRemotePort ());
6371 pMessageForward->PushCell (m_webSocketServer_handle);
6472 pMessageForward->PushCell (pWebSocketClient->m_websocket_handle );
@@ -79,6 +87,11 @@ void WebSocketServer::OnOpen(ix::WebSocketOpenInfo openInfo, std::shared_ptr<ix:
7987 return ;
8088 }
8189
90+ {
91+ std::lock_guard<std::mutex> lock (m_headersMutex);
92+ m_connectionHeaders[connectionState->getId ()] = openInfo.headers ;
93+ }
94+
8295 g_TaskQueue.Push ([this , openInfo, connectionState]()
8396 {
8497 std::string remoteAddress = connectionState->getRemoteIp () + " :" + std::to_string (connectionState->getRemotePort ());
@@ -95,6 +108,13 @@ void WebSocketServer::OnClose(ix::WebSocketCloseInfo closeInfo, std::shared_ptr<
95108 {
96109 return ;
97110 }
111+
112+ std::string connectionId = connectionState->getId ();
113+
114+ {
115+ std::lock_guard<std::mutex> lock (m_headersMutex);
116+ m_connectionHeaders.erase (connectionId);
117+ }
98118
99119 g_TaskQueue.Push ([this , closeInfo, connectionState]()
100120 {
@@ -162,13 +182,13 @@ bool WebSocketServer::disconnectClient(const std::string& clientId) {
162182}
163183
164184std::vector<std::string> WebSocketServer::getClientIds () {
165- std::vector<std::string> clientIds;
185+ std::vector<std::string> clientIds;
166186
167- auto clients = m_webSocketServer.getClients ();
187+ auto clients = m_webSocketServer.getClients ();
168188
169- for (const auto & client : clients) {
170- clientIds.push_back (client.second );
171- }
189+ for (const auto & client : clients) {
190+ clientIds.push_back (client.second );
191+ }
172192
173- return clientIds;
193+ return clientIds;
174194}
0 commit comments