Skip to content

Commit

Permalink
Added option to echo back user agent for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
makdharma committed Feb 22, 2016
1 parent 31dd666 commit bfc7ada
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/cpp/interop/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static const char* kRandomFile = "test/cpp/interop/rnd.dat";

const char kEchoInitialMetadataKey[] = "x-grpc-test-echo-initial";
const char kEchoTrailingBinMetadataKey[] = "x-grpc-test-echo-trailing-bin";
const char kEchoUserAgentKey[] = "x-grpc-test-echo-useragent";

void MaybeEchoMetadata(ServerContext* context) {
const auto& client_metadata = context->client_metadata();
Expand All @@ -98,6 +99,15 @@ void MaybeEchoMetadata(ServerContext* context) {
kEchoTrailingBinMetadataKey,
grpc::string(iter->second.begin(), iter->second.end()));
}
// Check if client sent a magic key in the header that makes us echo
// back the user-agent (for testing purpose)
iter = client_metadata.find(kEchoUserAgentKey);
if (iter != client_metadata.end()) {
iter = client_metadata.find("user-agent");
if (iter != client_metadata.end()) {
context->AddInitialMetadata(kEchoUserAgentKey, iter->second.data());
}
}
}

bool SetPayload(PayloadType type, int size, Payload* payload) {
Expand Down Expand Up @@ -150,6 +160,7 @@ class TestServiceImpl : public TestService::Service {
public:
Status EmptyCall(ServerContext* context, const grpc::testing::Empty* request,
grpc::testing::Empty* response) {
MaybeEchoMetadata(context);
return Status::OK;
}

Expand Down

0 comments on commit bfc7ada

Please sign in to comment.