Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/extensions/path/rewrite/uri_template/v3/uri_template_rewrite.pb.h" 4 : #include "envoy/extensions/path/rewrite/uri_template/v3/uri_template_rewrite.pb.validate.h" 5 : #include "envoy/registry/registry.h" 6 : #include "envoy/router/path_rewriter.h" 7 : 8 : #include "source/extensions/path/rewrite/uri_template/uri_template_rewrite.h" 9 : 10 : namespace Envoy { 11 : namespace Extensions { 12 : namespace UriTemplate { 13 : namespace Rewrite { 14 : 15 : class UriTemplateRewriterFactory : public Router::PathRewriterFactory { 16 : public: 17 : absl::StatusOr<Router::PathRewriterSharedPtr> 18 44 : createPathRewriter(const Protobuf::Message& rewrite_config) override { 19 44 : auto path_rewrite_config = MessageUtil::downcastAndValidate< 20 44 : const envoy::extensions::path::rewrite::uri_template::v3::UriTemplateRewriteConfig&>( 21 44 : rewrite_config, ProtobufMessage::getStrictValidationVisitor()); 22 : 23 44 : if (!UriTemplate::isValidRewritePattern(path_rewrite_config.path_template_rewrite()).ok()) { 24 0 : return absl::InvalidArgumentError( 25 0 : fmt::format("path_rewrite_policy.path_template_rewrite {} is invalid", 26 0 : path_rewrite_config.path_template_rewrite())); 27 0 : } 28 44 : return std::make_shared<UriTemplateRewriter>(path_rewrite_config); 29 44 : } 30 : 31 : // Router::PathRewriterFactory 32 57 : ProtobufTypes::MessagePtr createEmptyConfigProto() override { 33 57 : return std::make_unique< 34 57 : envoy::extensions::path::rewrite::uri_template::v3::UriTemplateRewriteConfig>(); 35 57 : } 36 : 37 190 : std::string name() const override { 38 190 : return "envoy.path.rewrite.uri_template.uri_template_rewriter"; 39 190 : } 40 : }; 41 : 42 : DECLARE_FACTORY(UriTemplateRewriterFactory); 43 : 44 : } // namespace Rewrite 45 : } // namespace UriTemplate 46 : } // namespace Extensions 47 : } // namespace Envoy