Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick of https://github.com/envoyproxy/envoy/pull/9839 #132

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -81,6 +81,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 @@ -131,6 +131,9 @@ absl::optional<CelValue> ResponseWrapper::operator[](CelValue key) const {
return CelValue::CreateMap(&trailers_);
} else if (value == Flags) {
return CelValue::CreateInt64(info_.responseFlags());
} else if (value == TotalSize) {
return CelValue::CreateInt64(info_.bytesSent() + headers_.value_->byteSize().value() +
trailers_.value_->byteSize().value());
}
return {};
}
Expand Down
1 change: 1 addition & 0 deletions source/extensions/filters/common/expr/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class HeadersWrapper : public google::api::expr::runtime::CelMap {

private:
friend class RequestWrapper;
friend class ResponseWrapper;
const Http::HeaderMap* value_;
};

Expand Down
8 changes: 8 additions & 0 deletions test/extensions/filters/common/expr/context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ TEST(Context, ResponseAttributes) {
EXPECT_EQ(123, value.value().Int64OrDie());
}

{
auto value = response[CelValue::CreateString(TotalSize)];
EXPECT_TRUE(value.has_value());
ASSERT_TRUE(value.value().IsInt64());
EXPECT_EQ(148, value.value().Int64OrDie());
}


{
auto value = response[CelValue::CreateString(Code)];
EXPECT_TRUE(value.has_value());
Expand Down