Skip to content

Commit

Permalink
grpc: removing unused code (envoyproxy#29610)
Browse files Browse the repository at this point in the history
Risk Level: low
Testing: n/a
Docs Changes: n/a
Release Notes: n/a
envoyproxy/envoy-mobile#176

Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk authored Sep 14, 2023
1 parent 1b2c2d1 commit 8e7beb3
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 101 deletions.
38 changes: 0 additions & 38 deletions source/common/grpc/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,44 +284,6 @@ Common::prepareHeaders(const std::string& host_name, const std::string& service_
return message;
}

void Common::checkForHeaderOnlyError(Http::ResponseMessage& http_response) {
// First check for grpc-status in headers. If it is here, we have an error.
absl::optional<Status::GrpcStatus> grpc_status_code =
Common::getGrpcStatus(http_response.headers());
if (!grpc_status_code) {
return;
}

if (grpc_status_code.value() == Status::WellKnownGrpcStatus::InvalidCode) {
throw Exception(absl::optional<uint64_t>(), "bad grpc-status header");
}

throw Exception(grpc_status_code.value(), Common::getGrpcMessage(http_response.headers()));
}

void Common::validateResponse(Http::ResponseMessage& http_response) {
if (Http::Utility::getResponseStatus(http_response.headers()) != enumToInt(Http::Code::OK)) {
throw Exception(absl::optional<uint64_t>(), "non-200 response code");
}

checkForHeaderOnlyError(http_response);

// Check for existence of trailers.
if (!http_response.trailers()) {
throw Exception(absl::optional<uint64_t>(), "no response trailers");
}

absl::optional<Status::GrpcStatus> grpc_status_code =
Common::getGrpcStatus(*http_response.trailers());
if (!grpc_status_code || grpc_status_code.value() < 0) {
throw Exception(absl::optional<uint64_t>(), "bad grpc-status trailer");
}

if (grpc_status_code.value() != 0) {
throw Exception(grpc_status_code.value(), Common::getGrpcMessage(*http_response.trailers()));
}
}

const std::string& Common::typeUrlPrefix() {
CONSTRUCT_ON_FIRST_USE(std::string, "type.googleapis.com");
}
Expand Down
7 changes: 0 additions & 7 deletions source/common/grpc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ class Common {
const std::string& method_name,
const absl::optional<std::chrono::milliseconds>& timeout);

/**
* Basic validation of gRPC response, @throws Grpc::Exception in case of non successful response.
*/
static void validateResponse(Http::ResponseMessage& http_response);

/**
* @return const std::string& type URL prefix.
*/
Expand Down Expand Up @@ -223,8 +218,6 @@ class Common {
static absl::optional<RequestNames> resolveServiceAndMethod(const Http::HeaderEntry* path);

private:
static void checkForHeaderOnlyError(Http::ResponseMessage& http_response);

static constexpr size_t MAX_GRPC_TIMEOUT_VALUE = 99999999;
};

Expand Down
55 changes: 0 additions & 55 deletions test/common/grpc/common_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,61 +337,6 @@ TEST(GrpcContextTest, IsProtobufRequestHeader) {
EXPECT_FALSE(Common::isProtobufRequestHeaders(is_not));
}

TEST(GrpcContextTest, ValidateResponse) {
{
Http::ResponseMessageImpl response(
Http::ResponseHeaderMapPtr{new Http::TestResponseHeaderMapImpl{{":status", "200"}}});
response.trailers(
Http::ResponseTrailerMapPtr{new Http::TestResponseTrailerMapImpl{{"grpc-status", "0"}}});
EXPECT_NO_THROW(Common::validateResponse(response));
}
{
Http::ResponseMessageImpl response(
Http::ResponseHeaderMapPtr{new Http::TestResponseHeaderMapImpl{{":status", "503"}}});
EXPECT_THROW_WITH_MESSAGE(Common::validateResponse(response), Exception,
"non-200 response code");
}
{
Http::ResponseMessageImpl response(
Http::ResponseHeaderMapPtr{new Http::TestResponseHeaderMapImpl{{":status", "200"}}});
response.trailers(
Http::ResponseTrailerMapPtr{new Http::TestResponseTrailerMapImpl{{"grpc-status", "100"}}});
EXPECT_THROW_WITH_MESSAGE(Common::validateResponse(response), Exception,
"bad grpc-status trailer");
}
{
Http::ResponseMessageImpl response(
Http::ResponseHeaderMapPtr{new Http::TestResponseHeaderMapImpl{{":status", "200"}}});
response.trailers(
Http::ResponseTrailerMapPtr{new Http::TestResponseTrailerMapImpl{{"grpc-status", "4"}}});
EXPECT_THROW_WITH_MESSAGE(Common::validateResponse(response), Exception, "");
}
{
Http::ResponseMessageImpl response(
Http::ResponseHeaderMapPtr{new Http::TestResponseHeaderMapImpl{{":status", "200"}}});
response.trailers(Http::ResponseTrailerMapPtr{new Http::TestResponseTrailerMapImpl{
{"grpc-status", "4"}, {"grpc-message", "custom error"}}});
EXPECT_THROW_WITH_MESSAGE(Common::validateResponse(response), Exception, "custom error");
}
{
Http::ResponseMessageImpl response(Http::ResponseHeaderMapPtr{
new Http::TestResponseHeaderMapImpl{{":status", "200"}, {"grpc-status", "100"}}});
EXPECT_THROW_WITH_MESSAGE(Common::validateResponse(response), Exception,
"bad grpc-status header");
}
{
Http::ResponseMessageImpl response(Http::ResponseHeaderMapPtr{
new Http::TestResponseHeaderMapImpl{{":status", "200"}, {"grpc-status", "4"}}});
EXPECT_THROW_WITH_MESSAGE(Common::validateResponse(response), Exception, "");
}
{
Http::ResponseMessageImpl response(
Http::ResponseHeaderMapPtr{new Http::TestResponseHeaderMapImpl{
{":status", "200"}, {"grpc-status", "4"}, {"grpc-message", "custom error"}}});
EXPECT_THROW_WITH_MESSAGE(Common::validateResponse(response), Exception, "custom error");
}
}

// Ensure that the correct gPRC header is constructed for a Buffer::Instance.
TEST(GrpcContextTest, PrependGrpcFrameHeader) {
auto buffer = std::make_unique<Buffer::OwnedImpl>();
Expand Down
1 change: 0 additions & 1 deletion tools/code_format/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ paths:
- source/common/secret/secret_manager_impl.cc
- source/common/secret/sds_api.cc
- source/common/grpc/async_client_manager_impl.cc
- source/common/grpc/common.cc
- source/common/grpc/google_grpc_utils.cc
- source/common/tcp_proxy/tcp_proxy.cc
- source/common/config/subscription_factory_impl.cc
Expand Down

0 comments on commit 8e7beb3

Please sign in to comment.