Skip to content

Commit

Permalink
context: add response.total_size (#9839)
Browse files Browse the repository at this point in the history
Signed-off-by: Kuat Yessenov <kuat@google.com>
  • Loading branch information
kyessenov authored and mattklein123 committed Jan 28, 2020
1 parent e342011 commit 7fff628
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/root/intro/arch_overview/security/rbac_filter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions source/extensions/filters/common/expr/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ absl::optional<CelValue> 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 {};
}
Expand Down
7 changes: 7 additions & 0 deletions test/extensions/filters/common/expr/context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 7fff628

Please sign in to comment.