aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/grpc++/channel_arguments.h3
-rw-r--r--src/cpp/client/channel.cc6
-rw-r--r--src/cpp/client/channel_arguments.cc9
3 files changed, 16 insertions, 2 deletions
diff --git a/include/grpc++/channel_arguments.h b/include/grpc++/channel_arguments.h
index f450d1602c..e4881b7828 100644
--- a/include/grpc++/channel_arguments.h
+++ b/include/grpc++/channel_arguments.h
@@ -70,6 +70,9 @@ class ChannelArguments {
ChannelArguments(const ChannelArguments&);
ChannelArguments& operator=(const ChannelArguments&);
+ // Returns empty string when it is not set.
+ grpc::string GetSslTargetNameOverride() const;
+
// Populates given channel_args with args_, does not take ownership.
void SetChannelArgs(grpc_channel_args* channel_args) const;
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;