u
This commit is contained in:
@@ -83,18 +83,19 @@ static void handle_request(tls_session* sess) {
|
|||||||
size_t resp_size = resp_body.size();
|
size_t resp_size = resp_body.size();
|
||||||
|
|
||||||
// Console log with response size and truncated body
|
// Console log with response size and truncated body
|
||||||
|
const char* ip = sess->peer_ip.c_str();
|
||||||
if (resp_size > 0) {
|
if (resp_size > 0) {
|
||||||
std::string preview = resp_body.substr(0, std::min(resp_size, (size_t)200));
|
std::string preview = resp_body.substr(0, std::min(resp_size, (size_t)200));
|
||||||
logc::info("127.0.0.1 %s %s %d %dms [%zu bytes] %s",
|
logc::info("%s %s %s %d %dms [%zu bytes] %s",
|
||||||
req.method.c_str(), url.c_str(), resp.status_code,
|
ip, req.method.c_str(), url.c_str(), resp.status_code,
|
||||||
(int)elapsed, resp_size, preview.c_str());
|
(int)elapsed, resp_size, preview.c_str());
|
||||||
} else {
|
} else {
|
||||||
logc::info("127.0.0.1 %s %s %d %dms",
|
logc::info("%s %s %s %d %dms",
|
||||||
req.method.c_str(), url.c_str(), resp.status_code, (int)elapsed);
|
ip, req.method.c_str(), url.c_str(), resp.status_code, (int)elapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request log
|
// Request log
|
||||||
request_log.log("127.0.0.1", req.method, url, resp.status_code, (int)elapsed, resp_body);
|
request_log.log(ip, req.method, url, resp.status_code, (int)elapsed, resp_body);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -197,7 +197,6 @@ static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
|
|||||||
int ret = SSL_do_handshake(sess->ssl);
|
int ret = SSL_do_handshake(sess->ssl);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
sess->handshake_done = true;
|
sess->handshake_done = true;
|
||||||
logc::info("TLS handshake complete");
|
|
||||||
flush_encrypted(sess);
|
flush_encrypted(sess);
|
||||||
} else {
|
} else {
|
||||||
int err = SSL_get_error(sess->ssl, ret);
|
int err = SSL_get_error(sess->ssl, ret);
|
||||||
@@ -276,7 +275,7 @@ static void on_connection(uv_stream_t* server, int status) {
|
|||||||
uv_ip4_name(reinterpret_cast<struct sockaddr_in*>(&saddr), addr_buf, sizeof(addr_buf));
|
uv_ip4_name(reinterpret_cast<struct sockaddr_in*>(&saddr), addr_buf, sizeof(addr_buf));
|
||||||
else
|
else
|
||||||
uv_ip6_name(reinterpret_cast<struct sockaddr_in6*>(&saddr), addr_buf, sizeof(addr_buf));
|
uv_ip6_name(reinterpret_cast<struct sockaddr_in6*>(&saddr), addr_buf, sizeof(addr_buf));
|
||||||
logc::info("TLS connection from %s", addr_buf);
|
sess->peer_ip = addr_buf;
|
||||||
|
|
||||||
// Read encrypted data
|
// Read encrypted data
|
||||||
uv_read_start(reinterpret_cast<uv_stream_t*>(&sess->tcp_handle), on_alloc, on_read);
|
uv_read_start(reinterpret_cast<uv_stream_t*>(&sess->tcp_handle), on_alloc, on_read);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ struct tls_session {
|
|||||||
|
|
||||||
bool handshake_done = false;
|
bool handshake_done = false;
|
||||||
uint32_t body_length = 0;
|
uint32_t body_length = 0;
|
||||||
|
std::string peer_ip;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user