diff --git a/docs/root/intro/arch_overview/security/rbac_filter.rst b/docs/root/intro/arch_overview/security/rbac_filter.rst index f9483d8c6e6ce..f5c22ebfef819 100644 --- a/docs/root/intro/arch_overview/security/rbac_filter.rst +++ b/docs/root/intro/arch_overview/security/rbac_filter.rst @@ -83,6 +83,7 @@ The following attributes are exposed to the language runtime: response.headers, string map, All response headers response.trailers, string map, All response trailers response.size, int, Size of the response body + response.total_size, int, Total size of the response including the approximate uncompressed size of the headers and the trailers response.flags, int, Additional details about the response beyond the standard response code source.address, string, Downstream connection remote address source.port, int, Downstream connection remote port diff --git a/source/extensions/filters/common/expr/context.cc b/source/extensions/filters/common/expr/context.cc index 010c92784b9da..6ae0eef652d34 100644 --- a/source/extensions/filters/common/expr/context.cc +++ b/source/extensions/filters/common/expr/context.cc @@ -147,6 +147,9 @@ absl::optional ResponseWrapper::operator[](CelValue key) const { return CelValue::CreateInt64(optional_status.value()); } return {}; + } else if (value == TotalSize) { + return CelValue::CreateInt64(info_.bytesSent() + headers_.value_->byteSize() + + trailers_.value_->byteSize()); } return {}; } diff --git a/test/extensions/filters/common/expr/context_test.cc b/test/extensions/filters/common/expr/context_test.cc index 7beeafcfaab4d..8768d811a2f1f 100644 --- a/test/extensions/filters/common/expr/context_test.cc +++ b/test/extensions/filters/common/expr/context_test.cc @@ -223,6 +223,13 @@ TEST(Context, ResponseAttributes) { EXPECT_EQ(123, value.value().Int64OrDie()); } + { + auto value = response[CelValue::CreateStringView(TotalSize)]; + EXPECT_TRUE(value.has_value()); + ASSERT_TRUE(value.value().IsInt64()); + EXPECT_EQ(160, value.value().Int64OrDie()); + } + { auto value = response[CelValue::CreateStringView(Code)]; EXPECT_TRUE(value.has_value());