forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first commit to use formatter context
Signed-off-by: wbpcode <wbphub@live.com>
- Loading branch information
Showing
40 changed files
with
312 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
|
||
|
||
#pragma once | ||
|
||
#include "envoy/data/accesslog/v3/accesslog.pb.h" | ||
#include "envoy/http/header_map.h" | ||
|
||
namespace Envoy { | ||
namespace Formatter { | ||
|
||
using AccessLogType = envoy::data::accesslog::v3::AccessLogType; | ||
|
||
/** | ||
* HTTP specific substitution formatter context for HTTP access logs or formatters. | ||
*/ | ||
class HttpFormatterContext { | ||
public: | ||
/** | ||
* Constructor that uses the provided request/response headers, response trailers, local reply | ||
* body, and access log type. Any of the parameters can be nullptr/empty. | ||
* | ||
* @param request_headers supplies the request headers. | ||
* @param response_headers supplies the response headers. | ||
* @param response_trailers supplies the response trailers. | ||
* @param local_reply_body supplies the local reply body. | ||
* @param log_type supplies the access log type. | ||
*/ | ||
HttpFormatterContext(const Http::RequestHeaderMap* request_headers = nullptr, | ||
const Http::ResponseHeaderMap* response_headers = nullptr, | ||
const Http::ResponseTrailerMap* response_trailers = nullptr, | ||
absl::string_view local_reply_body = {}, | ||
AccessLogType log_type = AccessLogType::NotSet); | ||
/** | ||
* Set or overwrite the request headers. | ||
* @param request_headers supplies the request headers. | ||
*/ | ||
HttpFormatterContext& setRequestHeaders(const Http::RequestHeaderMap& request_headers) { | ||
request_headers_ = &request_headers; | ||
return *this; | ||
} | ||
/** | ||
* Set or overwrite the response headers. | ||
* @param response_headers supplies the response headers. | ||
*/ | ||
HttpFormatterContext& setResponseHeaders(const Http::ResponseHeaderMap& response_headers) { | ||
response_headers_ = &response_headers; | ||
return *this; | ||
} | ||
|
||
/** | ||
* Set or overwrite the response trailers. | ||
* @param response_trailers supplies the response trailers. | ||
*/ | ||
HttpFormatterContext& setResponseTrailers(const Http::ResponseTrailerMap& response_trailers) { | ||
response_trailers_ = &response_trailers; | ||
return *this; | ||
} | ||
|
||
/** | ||
* Set or overwrite the local reply body. | ||
* @param local_reply_body supplies the local reply body. | ||
*/ | ||
HttpFormatterContext& setLocalReplyBody(absl::string_view local_reply_body) { | ||
local_reply_body_ = local_reply_body; | ||
return *this; | ||
} | ||
|
||
/** | ||
* Set or overwrite the access log type. | ||
* @param log_type supplies the access log type. | ||
*/ | ||
HttpFormatterContext& setAccessLogType(AccessLogType log_type) { | ||
log_type_ = log_type; | ||
return *this; | ||
} | ||
|
||
/** | ||
* @return const Http::RequestHeaderMap& the request headers. Empty request header map if no | ||
* request headers are available. | ||
*/ | ||
const Http::RequestHeaderMap& requestHeaders() const; | ||
|
||
/** | ||
* @return const Http::ResponseHeaderMap& the response headers. Empty respnose header map if | ||
* no response headers are available. | ||
*/ | ||
const Http::ResponseHeaderMap& responseHeaders() const; | ||
|
||
/** | ||
* @return const Http::ResponseTrailerMap& the response trailers. Empty response trailer map | ||
* if no response trailers are available. | ||
*/ | ||
const Http::ResponseTrailerMap& responseTrailers() const; | ||
|
||
/** | ||
* @return absl::string_view the local reply body. Empty if no local reply body. | ||
*/ | ||
absl::string_view localReplyBody() const; | ||
|
||
/** | ||
* @return AccessLog::AccessLogType the type of access log. NotSet if this is not used for | ||
* access logging. | ||
*/ | ||
AccessLogType accessLogType() const; | ||
|
||
private: | ||
const Http::RequestHeaderMap* request_headers_{}; | ||
const Http::ResponseHeaderMap* response_headers_{}; | ||
const Http::ResponseTrailerMap* response_trailers_{}; | ||
absl::string_view local_reply_body_{}; | ||
AccessLogType log_type_{AccessLogType::NotSet}; | ||
}; | ||
|
||
} // namespace Formatter | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.