diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 2813e13abea..4594cbaeb6f 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -94,6 +94,10 @@ class ClientContext { void set_absolute_deadline(const system_clock::time_point &deadline); system_clock::time_point absolute_deadline(); + void set_authority(const grpc::string& authority) { + authority_ = authority; + } + void TryCancel(); private: @@ -137,10 +141,15 @@ class ClientContext { gpr_timespec RawDeadline() { return absolute_deadline_; } + grpc::string authority() { + return authority_; + } + bool initial_metadata_received_ = false; grpc_call *call_; grpc_completion_queue *cq_; gpr_timespec absolute_deadline_; + grpc::string authority_; std::multimap send_initial_metadata_; std::multimap recv_initial_metadata_; std::multimap trailing_metadata_; diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index 440423dba96..c4794d717d0 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -81,8 +81,11 @@ Channel::~Channel() { grpc_channel_destroy(c_channel_); } Call Channel::CreateCall(const RpcMethod &method, ClientContext *context, CompletionQueue *cq) { auto c_call = - grpc_channel_create_call(c_channel_, cq->cq(), method.name(), - target_.c_str(), context->RawDeadline()); + grpc_channel_create_call( + c_channel_, cq->cq(), method.name(), + context->authority().empty() ? target_.c_str() + : context->authority(), + context->RawDeadline()); context->set_call(c_call); return Call(c_call, this, cq); }