LCOV - code coverage report
Current view: top level - envoy/router - path_rewriter.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 3 4 75.0 %
Date: 2024-01-05 06:35:25 Functions: 3 4 75.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/config/typed_config.h"
       4             : #include "envoy/router/path_matcher.h"
       5             : 
       6             : #include "source/common/common/logger.h"
       7             : 
       8             : #include "absl/status/statusor.h"
       9             : #include "absl/strings/string_view.h"
      10             : 
      11             : namespace Envoy {
      12             : namespace Router {
      13             : 
      14             : /**
      15             :  * Creates the new route path based on the provided rewrite pattern.
      16             :  * Subclassing Logger::Loggable so that implementations can log details.
      17             :  */
      18             : class PathRewriter : Logger::Loggable<Logger::Id::router> {
      19             : public:
      20         145 :   PathRewriter() = default;
      21         145 :   virtual ~PathRewriter() = default;
      22             : 
      23             :   /**
      24             :    * Determines if the matcher policy is compatible.
      25             :    *
      26             :    * @param path_match_policy current path match policy for route
      27             :    * @return true if current path match policy is acceptable
      28             :    */
      29             :   virtual absl::Status isCompatiblePathMatcher(PathMatcherSharedPtr path_matcher) const PURE;
      30             : 
      31             :   /**
      32             :    * Rewrites the current path to the specified output. Return a failure in case rewrite
      33             :    * is not successful.
      34             :    *
      35             :    * @param path current path of route
      36             :    * @param rewrite_pattern pattern to rewrite the path to
      37             :    * @return the rewritten path.
      38             :    */
      39             :   virtual absl::StatusOr<std::string> rewritePath(absl::string_view path,
      40             :                                                   absl::string_view rewrite_pattern) const PURE;
      41             : 
      42             :   /**
      43             :    * @return the rewrite uri_template.
      44             :    */
      45             :   virtual absl::string_view uriTemplate() const PURE;
      46             : 
      47             :   /**
      48             :    * @return the name of the pattern rewriter.
      49             :    */
      50             :   virtual absl::string_view name() const PURE;
      51             : };
      52             : 
      53             : using PathRewriterSharedPtr = std::shared_ptr<PathRewriter>;
      54             : 
      55             : /**
      56             :  * Factory for PathRewriter.
      57             :  */
      58             : class PathRewriterFactory : public Envoy::Config::TypedFactory {
      59             : public:
      60           0 :   ~PathRewriterFactory() override = default;
      61             : 
      62             :   /**
      63             :    * @param rewrite_config contains the proto stored in TypedExtensionConfig.
      64             :    * @return an PathRewriterSharedPtr.
      65             :    */
      66             :   virtual absl::StatusOr<PathRewriterSharedPtr>
      67             :   createPathRewriter(const Protobuf::Message& rewrite_config) PURE;
      68             : 
      69             :   ProtobufTypes::MessagePtr createEmptyConfigProto() override PURE;
      70             : 
      71             :   /**
      72             :    * @return the name of the pattern rewriter to be created.
      73             :    */
      74             :   std::string name() const override PURE;
      75             : 
      76             :   /**
      77             :    * @return the category of the pattern rewriter to be created.
      78             :    */
      79         112 :   std::string category() const override { return "envoy.path.rewrite"; }
      80             : };
      81             : 
      82             : } // namespace Router
      83             : } // namespace Envoy

Generated by: LCOV version 1.15