aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/interop/server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp/interop/server.cc')
-rw-r--r--test/cpp/interop/server.cc35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index cdca060c23..18ac35d551 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -80,6 +80,36 @@ using grpc::Status;
static bool got_sigint = false;
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();
+ GPR_ASSERT(client_metadata.count(kEchoInitialMetadataKey) <= 1);
+ GPR_ASSERT(client_metadata.count(kEchoTrailingBinMetadataKey) <= 1);
+
+ auto iter = client_metadata.find(kEchoInitialMetadataKey);
+ if (iter != client_metadata.end()) {
+ context->AddInitialMetadata(kEchoInitialMetadataKey, iter->second.data());
+ }
+ iter = client_metadata.find(kEchoTrailingBinMetadataKey);
+ if (iter != client_metadata.end()) {
+ context->AddTrailingMetadata(
+ 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) {
PayloadType response_type;
if (type == PayloadType::RANDOM) {
@@ -130,11 +160,13 @@ class TestServiceImpl : public TestService::Service {
public:
Status EmptyCall(ServerContext* context, const grpc::testing::Empty* request,
grpc::testing::Empty* response) {
+ MaybeEchoMetadata(context);
return Status::OK;
}
Status UnaryCall(ServerContext* context, const SimpleRequest* request,
SimpleResponse* response) {
+ MaybeEchoMetadata(context);
SetResponseCompression(context, *request);
if (request->response_size() > 0) {
if (!SetPayload(request->response_type(), request->response_size(),
@@ -192,6 +224,7 @@ class TestServiceImpl : public TestService::Service {
ServerContext* context,
ServerReaderWriter<StreamingOutputCallResponse,
StreamingOutputCallRequest>* stream) {
+ MaybeEchoMetadata(context);
StreamingOutputCallRequest request;
StreamingOutputCallResponse response;
bool write_success = true;