Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
move x-http-method-override to beginning of filter chain (#801)
Create a new filter to handle method override. Tested via integration test.
- Loading branch information
Showing
25 changed files
with
474 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| load("@envoy_api//bazel:api_build_system.bzl", "api_cc_py_proto_library") | ||
| load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| api_cc_py_proto_library( | ||
| name = "config_proto", | ||
| srcs = [ | ||
| "config.proto", | ||
| ], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| go_proto_library( | ||
| name = "config_go_proto", | ||
| importpath = "github.com/GoogleCloudPlatform/esp-v2/src/go/proto/api/envoy/v11/http/header_sanitizer", | ||
| proto = ":config_proto", | ||
| ) |
This file contains 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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright 2023 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| syntax = "proto3"; | ||
|
|
||
| package espv2.api.envoy.v11.http.header_sanitizer; | ||
|
|
||
| // header_sanitizer filter doesn't need any config. | ||
| // But a config protobuf type is required by FilterFactory. | ||
| // Hence defines an empty FilterConfig here. | ||
| message FilterConfig {} |
This file contains 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 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 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 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 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 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 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 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 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| load( | ||
| "@envoy//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_cc_test", | ||
| ) | ||
|
|
||
| package( | ||
| default_visibility = [ | ||
| "//src/envoy:__subpackages__", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "filter_lib", | ||
| srcs = [ | ||
| "filter.cc", | ||
| ], | ||
| hdrs = [ | ||
| "filter.h", | ||
| ], | ||
| repository = "@envoy", | ||
| deps = [ | ||
| "//src/envoy/utils:http_header_utils_lib", | ||
| "//src/envoy/utils:rc_detail_utils_lib", | ||
| "@envoy//envoy/stats:stats_interface", | ||
| "@envoy//source/extensions/filters/http/common:pass_through_filter_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "filter_factory", | ||
| srcs = ["filter_factory.cc"], | ||
| repository = "@envoy", | ||
| deps = [ | ||
| ":filter_lib", | ||
| "//api/envoy/v11/http/header_sanitizer:config_proto_cc_proto", | ||
| "@envoy//source/exe:envoy_common_lib", | ||
| ], | ||
| ) |
This file contains 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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2023 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "src/envoy/http/header_sanitizer/filter.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/http/header_map.h" | ||
| #include "source/common/http/headers.h" | ||
| #include "source/common/http/utility.h" | ||
| #include "src/envoy/utils/http_header_utils.h" | ||
| #include "src/envoy/utils/rc_detail_utils.h" | ||
|
|
||
| namespace espv2 { | ||
| namespace envoy { | ||
| namespace http_filters { | ||
| namespace header_sanitizer { | ||
|
|
||
| using Envoy::Http::FilterDataStatus; | ||
| using Envoy::Http::FilterHeadersStatus; | ||
| using Envoy::Http::FilterTrailersStatus; | ||
| using Envoy::Http::RequestHeaderMap; | ||
|
|
||
| FilterHeadersStatus Filter::decodeHeaders(RequestHeaderMap& headers, bool) { | ||
| if (utils::handleHttpMethodOverride(headers)) { | ||
| // Update later filters that the HTTP method has changed by clearing the | ||
| // route cache. | ||
| ENVOY_LOG(debug, "HTTP method override occurred, recalculating route"); | ||
| decoder_callbacks_->downstreamCallbacks()->clearRouteCache(); | ||
| } | ||
|
|
||
| return FilterHeadersStatus::Continue; | ||
| } | ||
|
|
||
| } // namespace header_sanitizer | ||
| } // namespace http_filters | ||
| } // namespace envoy | ||
| } // namespace espv2 |
This file contains 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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright 2023 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "envoy/http/filter.h" | ||
| #include "envoy/http/header_map.h" | ||
| #include "source/common/common/logger.h" | ||
| #include "source/extensions/filters/http/common/pass_through_filter.h" | ||
|
|
||
| namespace espv2 { | ||
| namespace envoy { | ||
| namespace http_filters { | ||
| namespace header_sanitizer { | ||
|
|
||
| class Filter : public Envoy::Http::PassThroughDecoderFilter, | ||
| public Envoy::Logger::Loggable<Envoy::Logger::Id::filter> { | ||
| public: | ||
| Filter() = default; | ||
|
|
||
| // Envoy::Http::StreamDecoderFilter | ||
| Envoy::Http::FilterHeadersStatus decodeHeaders(Envoy::Http::RequestHeaderMap&, | ||
| bool) override; | ||
| }; | ||
|
|
||
| } // namespace header_sanitizer | ||
| } // namespace http_filters | ||
| } // namespace envoy | ||
| } // namespace espv2 |
This file contains 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 |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright 2023 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "api/envoy/v11/http/header_sanitizer/config.pb.h" | ||
| #include "api/envoy/v11/http/header_sanitizer/config.pb.validate.h" | ||
| #include "envoy/registry/registry.h" | ||
| #include "source/extensions/filters/http/common/factory_base.h" | ||
| #include "src/envoy/http/header_sanitizer/filter.h" | ||
|
|
||
| namespace espv2 { | ||
| namespace envoy { | ||
| namespace http_filters { | ||
| namespace header_sanitizer { | ||
|
|
||
| constexpr const char kFilterName[] = | ||
| "com.google.espv2.filters.http.header_sanitizer"; | ||
|
|
||
| /** | ||
| * Config registration for ESPv2 header sanitizer filter. | ||
| */ | ||
| class FilterFactory | ||
| : public Envoy::Extensions::HttpFilters::Common::FactoryBase< | ||
| ::espv2::api::envoy::v11::http::header_sanitizer::FilterConfig> { | ||
| public: | ||
| FilterFactory() : FactoryBase(kFilterName) {} | ||
|
|
||
| private: | ||
| Envoy::Http::FilterFactoryCb createFilterFactoryFromProtoTyped( | ||
| const ::espv2::api::envoy::v11::http::header_sanitizer::FilterConfig&, | ||
| const std::string&, | ||
| Envoy::Server::Configuration::FactoryContext&) override { | ||
| return [](Envoy::Http::FilterChainFactoryCallbacks& callbacks) -> void { | ||
| auto filter = std::make_shared<Filter>(); | ||
| callbacks.addStreamDecoderFilter(filter); | ||
| }; | ||
| } | ||
| }; | ||
| /** | ||
| * Static registration for the filter. @see RegisterFactory. | ||
| */ | ||
| static Envoy::Registry::RegisterFactory< | ||
| FilterFactory, Envoy::Server::Configuration::NamedHttpFilterConfigFactory> | ||
| register_; | ||
|
|
||
| } // namespace header_sanitizer | ||
| } // namespace http_filters | ||
| } // namespace envoy | ||
| } // namespace espv2 |
This file contains 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 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
Oops, something went wrong.