diff options
Diffstat (limited to 'src/cpp/client')
-rw-r--r-- | src/cpp/client/channel.cc | 6 | ||||
-rw-r--r-- | src/cpp/client/channel_arguments.cc | 9 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index b54673c414..7a21ec1804 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -64,11 +64,13 @@ Channel::Channel(const grpc::string& target, const ChannelArguments& args) Channel::Channel(const grpc::string& target, const std::unique_ptr<Credentials>& creds, const ChannelArguments& args) - : target_(target) { + : target_(args.GetSslTargetNameOverride().empty() + ? target + : args.GetSslTargetNameOverride()) { grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); c_channel_ = grpc_secure_channel_create( - creds->GetRawCreds(), target_.c_str(), + creds->GetRawCreds(), target.c_str(), channel_args.num_args > 0 ? &channel_args : nullptr); } diff --git a/src/cpp/client/channel_arguments.cc b/src/cpp/client/channel_arguments.cc index 7d6bd4e874..cc888c1091 100644 --- a/src/cpp/client/channel_arguments.cc +++ b/src/cpp/client/channel_arguments.cc @@ -41,6 +41,15 @@ void ChannelArguments::SetSslTargetNameOverride(const grpc::string& name) { SetString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, name); } +grpc::string ChannelArguments::GetSslTargetNameOverride() const { + for (int i = 0; i < args_.size(); i++) { + if (grpc::string(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == args_[i].key) { + return args_[i].value.string; + } + } + return ""; +} + void ChannelArguments::SetInt(const grpc::string& key, int value) { grpc_arg arg; arg.type = GRPC_ARG_INTEGER; |