diff --git a/src/core/ext/filters/stateful_session/stateful_session_filter.cc b/src/core/ext/filters/stateful_session/stateful_session_filter.cc index 472f03bdb2b..cd59e0904bc 100644 --- a/src/core/ext/filters/stateful_session/stateful_session_filter.cc +++ b/src/core/ext/filters/stateful_session/stateful_session_filter.cc @@ -261,9 +261,11 @@ void StatefulSessionFilter::Call::OnClientInitialMetadata( cluster_name_ = GetClusterToUse(host_cluster.second, service_config_call_data); cluster_changed_ = cluster_name_ != host_cluster.second; + perform_filtering_ = true; } void StatefulSessionFilter::Call::OnServerInitialMetadata(ServerMetadata& md) { + if (!perform_filtering_) return; // Add cookie to server initial metadata if needed. MaybeUpdateServerInitialMetadata(cookie_config_, cluster_changed_, cluster_name_, cookie_address_list_, @@ -271,6 +273,7 @@ void StatefulSessionFilter::Call::OnServerInitialMetadata(ServerMetadata& md) { } void StatefulSessionFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) { + if (!perform_filtering_) return; // If we got a Trailers-Only response, then add the // cookie to the trailing metadata instead of the // initial metadata. diff --git a/src/core/ext/filters/stateful_session/stateful_session_filter.h b/src/core/ext/filters/stateful_session/stateful_session_filter.h index 79aac60a614..29b5c878dd9 100644 --- a/src/core/ext/filters/stateful_session/stateful_session_filter.h +++ b/src/core/ext/filters/stateful_session/stateful_session_filter.h @@ -93,6 +93,7 @@ class StatefulSessionFilter absl::string_view cluster_name_; absl::string_view cookie_address_list_; bool cluster_changed_; + bool perform_filtering_ = false; }; private: