1
#pragma once
2

            
3
#include <string>
4

            
5
#include "envoy/extensions/path/match/uri_template/v3/uri_template_match.pb.h"
6
#include "envoy/router/path_matcher.h"
7

            
8
#include "source/extensions/path/uri_template_lib/uri_template.h"
9

            
10
#include "absl/status/statusor.h"
11
#include "absl/strings/string_view.h"
12
#include "re2/re2.h"
13

            
14
namespace Envoy {
15
namespace Extensions {
16
namespace UriTemplate {
17
namespace Match {
18

            
19
const absl::string_view NAME = "envoy.path.match.uri_template.uri_template_matcher";
20

            
21
/**
22
 * UriTemplateMatcher allows matching based on uri templates.
23
 * Examples of several uri templates types are below:
24
 * Variable: /foo/bar/{var}
25
 *    Will match any path that starts with /foo/bar and has one additional segment
26
 * Literal: /foo/bar/goo
27
 *    Will match only a path of /foo/bar/goo
28
 */
29
class UriTemplateMatcher : public Router::PathMatcher {
30
public:
31
  explicit UriTemplateMatcher(
32
      const envoy::extensions::path::match::uri_template::v3::UriTemplateMatchConfig& config)
33
45
      : path_template_(config.path_template()),
34
45
        matching_pattern_regex_(convertPathPatternSyntaxToRegex(path_template_).value()) {}
35

            
36
  // Router::PathMatcher
37
  bool match(absl::string_view path) const override;
38
  absl::string_view uriTemplate() const override;
39
30
  absl::string_view name() const override { return NAME; }
40

            
41
private:
42
  const std::string path_template_;
43
  const RE2 matching_pattern_regex_;
44
};
45

            
46
} // namespace Match
47
} // namespace UriTemplate
48
} // namespace Extensions
49
} // namespace Envoy