Skip to content

Commit

Permalink
cors: remove unnecessary code (envoyproxy#37274)
Browse files Browse the repository at this point in the history
Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

Signed-off-by: wangbaiping(wbpcode) <[email protected]>
  • Loading branch information
wbpcode authored Nov 25, 2024
1 parent e317854 commit 4aa1d1b
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 298 deletions.
1 change: 1 addition & 0 deletions source/extensions/filters/http/cors/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ envoy_cc_library(
"//source/common/http:header_map_lib",
"//source/common/http:headers_lib",
"//source/common/http:utility_lib",
"//source/extensions/filters/http/common:pass_through_filter_lib",
"@com_google_absl//absl/container:inlined_vector",
],
)
Expand Down
4 changes: 0 additions & 4 deletions source/extensions/filters/http/cors/cors_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ Http::FilterHeadersStatus CorsFilter::encodeHeaders(Http::ResponseHeaderMap& hea
return Http::FilterHeadersStatus::Continue;
}

void CorsFilter::setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks& callbacks) {
decoder_callbacks_ = &callbacks;
}

bool CorsFilter::isOriginAllowed(const Http::HeaderString& origin) {
for (const auto& allow_origin : allowOrigins()) {
if (allow_origin->match("*") || allow_origin->match(origin.getStringView())) {
Expand Down
30 changes: 2 additions & 28 deletions source/extensions/filters/http/cors/cors_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "envoy/stats/stats_macros.h"

#include "source/common/buffer/buffer_impl.h"
#include "source/extensions/filters/http/common/pass_through_filter.h"

#include "absl/container/inlined_vector.h"

Expand Down Expand Up @@ -44,44 +45,19 @@ class CorsFilterConfig {
};
using CorsFilterConfigSharedPtr = std::shared_ptr<CorsFilterConfig>;

class CorsFilter : public Http::StreamFilter {
class CorsFilter : public Http::PassThroughFilter {
public:
CorsFilter(CorsFilterConfigSharedPtr config);

void initializeCorsPolicies();

// Http::StreamFilterBase
void onDestroy() override {}

// Http::StreamDecoderFilter
Http::FilterHeadersStatus decodeHeaders(Http::RequestHeaderMap& headers,
bool end_stream) override;
Http::FilterDataStatus decodeData(Buffer::Instance&, bool) override {
return Http::FilterDataStatus::Continue;
};
Http::FilterTrailersStatus decodeTrailers(Http::RequestTrailerMap&) override {
return Http::FilterTrailersStatus::Continue;
};
void setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks& callbacks) override;

// Http::StreamEncoderFilter
Http::Filter1xxHeadersStatus encode1xxHeaders(Http::ResponseHeaderMap&) override {
return Http::Filter1xxHeadersStatus::Continue;
}
Http::FilterHeadersStatus encodeHeaders(Http::ResponseHeaderMap& headers,
bool end_stream) override;
Http::FilterDataStatus encodeData(Buffer::Instance&, bool) override {
return Http::FilterDataStatus::Continue;
};
Http::FilterTrailersStatus encodeTrailers(Http::ResponseTrailerMap&) override {
return Http::FilterTrailersStatus::Continue;
};
Http::FilterMetadataStatus encodeMetadata(Http::MetadataMap&) override {
return Http::FilterMetadataStatus::Continue;
}
void setEncoderFilterCallbacks(Http::StreamEncoderFilterCallbacks& callbacks) override {
encoder_callbacks_ = &callbacks;
};

const auto& policiesForTest() const { return policies_; }

Expand All @@ -100,8 +76,6 @@ class CorsFilter : public Http::StreamFilter {
bool isOriginAllowed(const Http::HeaderString& origin);
bool forwardNotMatchingPreflights();

Http::StreamDecoderFilterCallbacks* decoder_callbacks_{};
Http::StreamEncoderFilterCallbacks* encoder_callbacks_{};
absl::InlinedVector<std::reference_wrapper<const Envoy::Router::CorsPolicy>, 4> policies_;
bool is_cors_request_{};
std::string latched_origin_;
Expand Down
Loading

0 comments on commit 4aa1d1b

Please sign in to comment.