This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 9.1.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 4cc21a5aead825e18aa9dd8638f9d4cd0846f27b Author: Susan Hinrichs <[email protected]> AuthorDate: Mon Apr 12 20:10:22 2021 -0500 Add sqpv log field for server protocol (#7680) (cherry picked from commit ae72bb9520d5f189f6997b0a0695b673d267496c) --- doc/admin-guide/logging/formatting.en.rst | 1 + proxy/http/HttpSM.cc | 2 ++ proxy/http/HttpSM.h | 1 + proxy/logging/Log.cc | 5 +++++ proxy/logging/LogAccess.cc | 34 +++++++++++++++++++++++++++++++ proxy/logging/LogAccess.h | 1 + 6 files changed, 44 insertions(+) diff --git a/doc/admin-guide/logging/formatting.en.rst b/doc/admin-guide/logging/formatting.en.rst index d9dbc1b..9a22000 100644 --- a/doc/admin-guide/logging/formatting.en.rst +++ b/doc/admin-guide/logging/formatting.en.rst @@ -567,6 +567,7 @@ Field Source Description cqhv Client Request Client request HTTP version. Deprecated since 9.0. Use ``cqpv`` instead. cqpv Client Request Client request protocol and version. +sqpv Proxy Request Origin negotiated protocol and version csshv Cached Proxy Response Origin server's HTTP version from cached version of the document in |TS| proxy cache. sshv Origin Response Origin server's response HTTP version. diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index 309bc9f..46eb118 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -6209,6 +6209,8 @@ HttpSM::attach_server_session(PoolableSession *s) server_connection_is_ssl = true; } + server_protocol = server_session->get_protocol_string(); + // Initiate a read on the session so that the SM and not // session manager will get called back if the timeout occurs // or the server closes on us. The IO Core now requires us to diff --git a/proxy/http/HttpSM.h b/proxy/http/HttpSM.h index da35e36..a48d552 100644 --- a/proxy/http/HttpSM.h +++ b/proxy/http/HttpSM.h @@ -548,6 +548,7 @@ public: bool is_using_post_buffer = false; std::optional<bool> mptcp_state; // Don't initialize, that marks it as "not defined". const char *client_protocol = "-"; + const char *server_protocol = "-"; const char *client_sec_protocol = "-"; const char *client_cipher_suite = "-"; const char *client_curve = "-"; diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc index c5965e8..5022eb0 100644 --- a/proxy/logging/Log.cc +++ b/proxy/logging/Log.cc @@ -452,6 +452,11 @@ Log::init_fields() global_field_list.add(field, false); field_symbol_hash.emplace("cqpv", field); + field = new LogField("server_req_protocol_version", "sqpv", LogField::dINT, &LogAccess::marshal_server_req_protocol_version, + reinterpret_cast<LogField::UnmarshalFunc>(&LogAccess::unmarshal_str)); + global_field_list.add(field, false); + field_symbol_hash.emplace("sqpv", field); + field = new LogField("client_req_header_len", "cqhl", LogField::sINT, &LogAccess::marshal_client_req_header_len, &LogAccess::unmarshal_int_to_str); global_field_list.add(field, false); diff --git a/proxy/logging/LogAccess.cc b/proxy/logging/LogAccess.cc index 02db557..75f6698 100644 --- a/proxy/logging/LogAccess.cc +++ b/proxy/logging/LogAccess.cc @@ -1786,6 +1786,40 @@ LogAccess::marshal_client_req_protocol_version(char *buf) -------------------------------------------------------------------------*/ int +LogAccess::marshal_server_req_protocol_version(char *buf) +{ + const char *protocol_str = m_http_sm->server_protocol; + int len = LogAccess::strlen(protocol_str); + + // Set major & minor versions when protocol_str is not "http/2". + if (::strlen(protocol_str) == 4 && strncmp("http", protocol_str, 4) == 0) { + if (m_proxy_request) { + HTTPVersion versionObject = m_proxy_request->version_get(); + int64_t major = HTTP_MAJOR(versionObject.m_version); + int64_t minor = HTTP_MINOR(versionObject.m_version); + if (major == 1 && minor == 1) { + protocol_str = "http/1.1"; + } else if (major == 1 && minor == 0) { + protocol_str = "http/1.0"; + } // else invalid http version + } else { + protocol_str = "*"; + } + + len = LogAccess::strlen(protocol_str); + } + + if (buf) { + marshal_str(buf, protocol_str, len); + } + + return len; +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +int LogAccess::marshal_client_req_header_len(char *buf) { if (buf) { diff --git a/proxy/logging/LogAccess.h b/proxy/logging/LogAccess.h index ff650ac..389bedc 100644 --- a/proxy/logging/LogAccess.h +++ b/proxy/logging/LogAccess.h @@ -143,6 +143,7 @@ public: inkcoreapi int marshal_client_req_url_scheme(char *); // STR inkcoreapi int marshal_client_req_http_version(char *); // INT inkcoreapi int marshal_client_req_protocol_version(char *); // STR + inkcoreapi int marshal_server_req_protocol_version(char *); // STR inkcoreapi int marshal_client_req_squid_len(char *); // INT inkcoreapi int marshal_client_req_header_len(char *); // INT inkcoreapi int marshal_client_req_content_len(char *); // INT
