| 100 | } |
| 101 | |
| 102 | FilterExpression getExpression(const std::string & expression, HTTPRequestFilterMatchType match_type, bool ignore_query_string) |
| 103 | { |
| 104 | if (match_type == HTTPRequestFilterMatchType::Prefix) |
| 105 | { |
| 106 | /// Match the value as a base path on a path-segment boundary (see checkExpression). A trailing '/' |
| 107 | /// is stripped here, so "/api/v1/" and "/api/v1" behave the same. |
| 108 | std::string_view value = expression; |
| 109 | if (value.ends_with('/')) |
| 110 | value.remove_suffix(1); |
| 111 | return {.value = String{value}, .match_prefix = true, .ignore_query_string = ignore_query_string}; |
| 112 | } |
| 113 | |
| 114 | /// `Regexp` treats the whole value as a regular expression, while `Full` does so only when the value |
| 115 | /// starts with the "regex:" marker. |
| 116 | if (match_type == HTTPRequestFilterMatchType::Regexp) |
| 117 | return {.value = expression, .regex = compileRegex(expression), .ignore_query_string = ignore_query_string}; |
| 118 | |
| 119 | if (startsWith(expression, "regex:")) |
| 120 | { |
| 121 | auto regex = expression.substr(strlen("regex:")); |
| 122 | return {.value = regex, .regex = compileRegex(regex), .ignore_query_string = ignore_query_string}; |
| 123 | } |
| 124 | |
| 125 | return {.value = expression, .ignore_query_string = ignore_query_string}; |
| 126 | } |
| 127 | |
| 128 | } |
| 129 |
no test coverage detected