diff options
author | yangg <yangg@google.com> | 2014-12-22 12:47:45 -0800 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2014-12-29 17:13:16 -0800 |
commit | 7cebec7ccddf412767433e3cc23a5791932b663c (patch) | |
tree | 2f1fe972605c046c95694edce13f304665160adb | |
parent | 5b7f32a2bb7a01e01456e6b64ac4976fe315122c (diff) |
Use overriden host name when creating a call.
Change on 2014/12/22 by yangg <yangg@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=82672321
-rw-r--r-- | include/grpc++/channel_arguments.h | 3 | ||||
-rw-r--r-- | src/cpp/client/channel.cc | 6 | ||||
-rw-r--r-- | src/cpp/client/channel_arguments.cc | 9 |
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; |