-
Notifications
You must be signed in to change notification settings - Fork 5.3k
access_log: Add %REQ_WITHOUT_QUERY()% formatter #7847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -222,7 +222,6 @@ void AccessLogFormatParser::parseCommand(const std::string& token, const size_t | |
| std::vector<FormatterProviderPtr> AccessLogFormatParser::parse(const std::string& format) { | ||
| std::string current_token; | ||
| std::vector<FormatterProviderPtr> formatters; | ||
| const std::string DYNAMIC_META_TOKEN = "DYNAMIC_METADATA("; | ||
| const std::regex command_w_args_regex(R"EOF(%([A-Z]|_)+(\([^\)]*\))?(:[0-9]+)?(%))EOF"); | ||
|
|
||
| for (size_t pos = 0; pos < format.length(); ++pos) { | ||
|
|
@@ -245,14 +244,16 @@ std::vector<FormatterProviderPtr> AccessLogFormatParser::parse(const std::string | |
| pos += 1; | ||
| int command_end_position = pos + token.length(); | ||
|
|
||
| if (absl::StartsWith(token, "REQ(")) { | ||
| const bool req_without_query = absl::StartsWith(token, "REQ_WITHOUT_QUERY("); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm looking at this code would it make more sense to have |
||
| if (absl::StartsWith(token, "REQ(") || req_without_query) { | ||
| std::string main_header, alternative_header; | ||
| absl::optional<size_t> max_length; | ||
|
|
||
| parseCommandHeader(token, ReqParamStart, main_header, alternative_header, max_length); | ||
| parseCommandHeader(token, req_without_query ? ReqWithoutQueryParamStart : ReqParamStart, | ||
| main_header, alternative_header, max_length); | ||
|
|
||
| formatters.emplace_back(FormatterProviderPtr{ | ||
| new RequestHeaderFormatter(main_header, alternative_header, max_length)}); | ||
| formatters.emplace_back(FormatterProviderPtr{new RequestHeaderFormatter( | ||
| main_header, alternative_header, max_length, req_without_query)}); | ||
| } else if (absl::StartsWith(token, "RESP(")) { | ||
| std::string main_header, alternative_header; | ||
| absl::optional<size_t> max_length; | ||
|
|
@@ -269,13 +270,13 @@ std::vector<FormatterProviderPtr> AccessLogFormatParser::parse(const std::string | |
|
|
||
| formatters.emplace_back(FormatterProviderPtr{ | ||
| new ResponseTrailerFormatter(main_header, alternative_header, max_length)}); | ||
| } else if (absl::StartsWith(token, DYNAMIC_META_TOKEN)) { | ||
| } else if (absl::StartsWith(token, "DYNAMIC_METADATA(")) { | ||
| std::string filter_namespace; | ||
| absl::optional<size_t> max_length; | ||
| std::vector<std::string> path; | ||
| const size_t start = DYNAMIC_META_TOKEN.size(); | ||
|
|
||
| parseCommand(token, start, ":", filter_namespace, path, max_length); | ||
| parseCommand(token, DynamicMetadataParamStart, ":", filter_namespace, path, max_length); | ||
|
|
||
| formatters.emplace_back( | ||
| FormatterProviderPtr{new DynamicMetadataFormatter(filter_namespace, path, max_length)}); | ||
| } else if (absl::StartsWith(token, "START_TIME")) { | ||
|
|
@@ -508,8 +509,9 @@ std::string PlainStringFormatter::format(const Http::HeaderMap&, const Http::Hea | |
|
|
||
| HeaderFormatter::HeaderFormatter(const std::string& main_header, | ||
| const std::string& alternative_header, | ||
| absl::optional<size_t> max_length) | ||
| : main_header_(main_header), alternative_header_(alternative_header), max_length_(max_length) {} | ||
| absl::optional<size_t> max_length, bool remove_query) | ||
| : main_header_(main_header), alternative_header_(alternative_header), max_length_(max_length), | ||
| remove_query_(remove_query) {} | ||
|
|
||
| std::string HeaderFormatter::format(const Http::HeaderMap& headers) const { | ||
| const Http::HeaderEntry* header = headers.get(main_header_); | ||
|
|
@@ -522,7 +524,14 @@ std::string HeaderFormatter::format(const Http::HeaderMap& headers) const { | |
| if (!header) { | ||
| header_value_string = UnspecifiedValueString; | ||
| } else { | ||
| header_value_string = std::string(header->value().getStringView()); | ||
| absl::string_view header_value = header->value().getStringView(); | ||
| if (remove_query_) { | ||
| const size_t query_pos = header_value.find('?'); | ||
| header_value_string = std::string( | ||
| header_value.data(), query_pos != header_value.npos ? query_pos : header_value.size()); | ||
| } else { | ||
| header_value_string = std::string(header_value); | ||
| } | ||
| } | ||
|
|
||
| if (max_length_ && header_value_string.length() > max_length_.value()) { | ||
|
|
@@ -535,7 +544,7 @@ std::string HeaderFormatter::format(const Http::HeaderMap& headers) const { | |
| ResponseHeaderFormatter::ResponseHeaderFormatter(const std::string& main_header, | ||
| const std::string& alternative_header, | ||
| absl::optional<size_t> max_length) | ||
| : HeaderFormatter(main_header, alternative_header, max_length) {} | ||
| : HeaderFormatter(main_header, alternative_header, max_length, false) {} | ||
|
|
||
| std::string ResponseHeaderFormatter::format(const Http::HeaderMap&, | ||
| const Http::HeaderMap& response_headers, | ||
|
|
@@ -546,8 +555,8 @@ std::string ResponseHeaderFormatter::format(const Http::HeaderMap&, | |
|
|
||
| RequestHeaderFormatter::RequestHeaderFormatter(const std::string& main_header, | ||
| const std::string& alternative_header, | ||
| absl::optional<size_t> max_length) | ||
| : HeaderFormatter(main_header, alternative_header, max_length) {} | ||
| absl::optional<size_t> max_length, bool remove_query) | ||
| : HeaderFormatter(main_header, alternative_header, max_length, remove_query) {} | ||
|
|
||
| std::string RequestHeaderFormatter::format(const Http::HeaderMap& request_headers, | ||
| const Http::HeaderMap&, const Http::HeaderMap&, | ||
|
|
@@ -558,7 +567,7 @@ std::string RequestHeaderFormatter::format(const Http::HeaderMap& request_header | |
| ResponseTrailerFormatter::ResponseTrailerFormatter(const std::string& main_header, | ||
| const std::string& alternative_header, | ||
| absl::optional<size_t> max_length) | ||
| : HeaderFormatter(main_header, alternative_header, max_length) {} | ||
| : HeaderFormatter(main_header, alternative_header, max_length, false) {} | ||
|
|
||
| std::string ResponseTrailerFormatter::format(const Http::HeaderMap&, const Http::HeaderMap&, | ||
| const Http::HeaderMap& response_trailers, | ||
|
|
||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this ever be used with any other header? wondering if it makes more sense to go with the other suggestion in the issue with making this a top level format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OH, I can also see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer that's why I went ahead with this. But yeah, probably a suffix operator is better?
REQ(X?Y):<MAX_LENGTH>:<POST_PROCESSING_OPERATOR>, e.g.REQ(:PATH):2:REMOVE_QUERY, REQ(:PATH):-:REMOVE_QUERY. Need to go back to discuss this in the issue then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as there are more than one header this makes sense for I'm fine with this. Are suffix operators something we currently support? I don't feel super strongly about either, would probably go with whichever has precedent