Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/envoy/api/v2/core/base.proto
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ enum RequestMethod {
CONNECT = 6;
OPTIONS = 7;
TRACE = 8;
PATCH = 9;
}

// Header name/value pair.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@ class HttpGrpcAccessLogTest : public testing::Test {
}));
}

void expectLogRequestMethod(const std::string& request_method) {
NiceMock<StreamInfo::MockStreamInfo> 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<AccessLog::MockFilter>()};
envoy::config::accesslog::v2::HttpGrpcAccessLogConfig config_;
std::shared_ptr<MockGrpcAccessLogStreamer> streamer_{new MockGrpcAccessLogStreamer()};
Expand Down Expand Up @@ -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);
}

{
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down