Merge pull request #6661 from Icinga/bugfix/cache-http-peer-address

Cache the peer address in the HTTP server
This commit is contained in:
Michael Friedrich 2018-10-09 16:00:27 +02:00 committed by GitHub
commit e6eb703b36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -47,6 +47,17 @@ HttpServerConnection::HttpServerConnection(const String& identity, bool authenti
if (authenticated)
m_ApiUser = ApiUser::GetByClientCN(identity);
/* Cache the peer address. */
m_PeerAddress = "<unknown>";
if (stream) {
Socket::Ptr socket = m_Stream->GetSocket();
if (socket) {
m_PeerAddress = socket->GetPeerAddress();
}
}
}
void HttpServerConnection::StaticInitialize()
@ -84,7 +95,7 @@ void HttpServerConnection::Disconnect()
}
Log(LogInformation, "HttpServerConnection")
<< "HTTP client disconnected (from " << m_Stream->GetSocket()->GetPeerAddress() << ")";
<< "HTTP client disconnected (from " << m_PeerAddress << ")";
ApiListener::Ptr listener = ApiListener::GetInstance();
listener->RemoveHttpClient(this);
@ -201,11 +212,9 @@ bool HttpServerConnection::ManageHeaders(HttpResponse& response)
String requestUrl = m_CurrentRequest.RequestUrl->Format();
Socket::Ptr socket = m_Stream->GetSocket();
Log(LogInformation, "HttpServerConnection")
<< "Request: " << m_CurrentRequest.RequestMethod << " " << requestUrl
<< " (from " << (socket ? socket->GetPeerAddress() : "<unkown>")
<< " (from " << m_PeerAddress << ")"
<< ", user: " << (m_AuthenticatedUser ? m_AuthenticatedUser->GetName() : "<unauthenticated>") << ")";
ApiListener::Ptr listener = ApiListener::GetInstance();

View File

@ -59,6 +59,7 @@ private:
boost::recursive_mutex m_DataHandlerMutex;
WorkQueue m_RequestQueue;
int m_PendingRequests;
String m_PeerAddress;
StreamReadContext m_Context;