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

grpc to support empty response. #1009

Merged
merged 2 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion source/common/grpc/rpc_channel_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void RpcChannelImpl::onSuccess(Http::MessagePtr&& http_response) {

// A gRPC response contains a 5 byte header. Currently we only support unary responses so we
// ignore the header. @see serializeBody().
if (!http_response->body() || !(http_response->body()->length() > 5)) {
if (!http_response->body() || !(http_response->body()->length() >= 5)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: http_response->body()->length() < 5, seems to be more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

throw Exception(Optional<uint64_t>(), "bad serialized body");
}

Expand Down
20 changes: 20 additions & 0 deletions test/common/grpc/rpc_channel_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,26 @@ TEST_F(GrpcRequestImplTest, ShortBodyInResponse) {
http_callbacks_->onSuccess(std::move(response_http_message));
}

TEST_F(GrpcRequestImplTest, EmptyBodyInResponse) {
expectNormalRequest();

helloworld::HelloRequest request;
request.set_name("a name");
helloworld::HelloReply response;
EXPECT_CALL(grpc_callbacks_, onPreRequestCustomizeHeaders(_));
service_.SayHello(nullptr, &request, &response, nullptr);

Http::MessagePtr response_http_message(new Http::ResponseMessageImpl(
Http::HeaderMapPtr{new Http::TestHeaderMapImpl{{":status", "200"}}}));
helloworld::HelloReply inner_response;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty_response might be more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

response_http_message->body() = Common::serializeBody(inner_response);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an EXPECT on the serialized body size being 5 bytes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

response_http_message->trailers(
Http::HeaderMapPtr{new Http::TestHeaderMapImpl{{"grpc-status", "0"}}});

EXPECT_CALL(grpc_callbacks_, onSuccess());
http_callbacks_->onSuccess(std::move(response_http_message));
}

TEST_F(GrpcRequestImplTest, BadMessageInResponse) {
expectNormalRequest();

Expand Down