From ce003d3d87404306b06975ea8550488c108ab3df Mon Sep 17 00:00:00 2001 From: Kuat Yessenov Date: Mon, 27 Jan 2020 11:29:46 -0800 Subject: [PATCH 1/2] context: add response.total_size Signed-off-by: Kuat Yessenov --- docs/root/intro/arch_overview/security/rbac_filter.rst | 1 + source/extensions/filters/common/expr/context.cc | 3 +++ test/extensions/filters/common/expr/context_test.cc | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/docs/root/intro/arch_overview/security/rbac_filter.rst b/docs/root/intro/arch_overview/security/rbac_filter.rst index f9483d8c6e6ce..01f3e73e0c731 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 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()); From 92d029913146c77f2bc70a4f92e77c3363618c30 Mon Sep 17 00:00:00 2001 From: Kuat Yessenov Date: Mon, 27 Jan 2020 15:08:35 -0800 Subject: [PATCH 2/2] clarify Signed-off-by: Kuat Yessenov --- docs/root/intro/arch_overview/security/rbac_filter.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/root/intro/arch_overview/security/rbac_filter.rst b/docs/root/intro/arch_overview/security/rbac_filter.rst index 01f3e73e0c731..f5c22ebfef819 100644 --- a/docs/root/intro/arch_overview/security/rbac_filter.rst +++ b/docs/root/intro/arch_overview/security/rbac_filter.rst @@ -83,7 +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 headers and the trailers + 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