diff --git a/api/envoy/api/v2/core/base.proto b/api/envoy/api/v2/core/base.proto index 6b4e931cfa405..949cbfc94afd5 100644 --- a/api/envoy/api/v2/core/base.proto +++ b/api/envoy/api/v2/core/base.proto @@ -140,6 +140,7 @@ enum RequestMethod { CONNECT = 6; OPTIONS = 7; TRACE = 8; + PATCH = 9; } // Header name/value pair. diff --git a/test/extensions/access_loggers/http_grpc/grpc_access_log_impl_test.cc b/test/extensions/access_loggers/http_grpc/grpc_access_log_impl_test.cc index 0502513f980e1..607379cc2a299 100644 --- a/test/extensions/access_loggers/http_grpc/grpc_access_log_impl_test.cc +++ b/test/extensions/access_loggers/http_grpc/grpc_access_log_impl_test.cc @@ -138,6 +138,36 @@ class HttpGrpcAccessLogTest : public testing::Test { })); } + void expectLogRequestMethod(const std::string& request_method) { + NiceMock stream_info; + stream_info.host_ = nullptr; + + Http::TestHeaderMapImpl request_headers{ + {":method", request_method}, + }; + + expectLog(fmt::format(R"EOF( + http_logs: + log_entry: + common_properties: + downstream_remote_address: + socket_address: + address: "127.0.0.1" + port_value: 0 + downstream_local_address: + socket_address: + address: "127.0.0.2" + port_value: 0 + start_time: {{}} + request: + request_method: {} + request_headers_bytes: {} + response: {{}} + )EOF", + request_method, request_method.length() + 7)); + access_log_->log(&request_headers, nullptr, nullptr, stream_info); + } + AccessLog::MockFilter* filter_{new NiceMock()}; envoy::config::accesslog::v2::HttpGrpcAccessLogConfig config_; std::shared_ptr streamer_{new MockGrpcAccessLogStreamer()}; @@ -333,9 +363,10 @@ TEST_F(HttpGrpcAccessLogTest, Marshalling) { upstream_transport_failure_reason: "TLS error" request: request_method: "METHOD_UNSPECIFIED" + request_headers_bytes: 16 response: {} )EOF"); - access_log_->log(nullptr, nullptr, nullptr, stream_info); + access_log_->log(&request_headers, nullptr, nullptr, stream_info); } { @@ -388,9 +419,10 @@ TEST_F(HttpGrpcAccessLogTest, Marshalling) { tls_session_id: D62A523A65695219D46FE1FFE285A4C371425ACE421B110B5B8D11D3EB4D5F0B request: request_method: "METHOD_UNSPECIFIED" + request_headers_bytes: 16 response: {} )EOF"); - access_log_->log(nullptr, nullptr, nullptr, stream_info); + access_log_->log(&request_headers, nullptr, nullptr, stream_info); } } @@ -509,6 +541,19 @@ TEST(responseFlagsToAccessLogResponseFlagsTest, All) { EXPECT_EQ(common_access_log_expected.DebugString(), common_access_log.DebugString()); } +TEST_F(HttpGrpcAccessLogTest, LogWithRequestMethod) { + InSequence s; + expectLogRequestMethod("GET"); + expectLogRequestMethod("HEAD"); + expectLogRequestMethod("POST"); + expectLogRequestMethod("PUT"); + expectLogRequestMethod("DELETE"); + expectLogRequestMethod("CONNECT"); + expectLogRequestMethod("OPTIONS"); + expectLogRequestMethod("TRACE"); + expectLogRequestMethod("PATCH"); +} + } // namespace } // namespace HttpGrpc } // namespace AccessLoggers