From b455bcc30101e41625753888626b17a5e48f6cdc Mon Sep 17 00:00:00 2001
From: Jan Tattermusch <jtattermusch@google.com>
Date: Tue, 22 Mar 2016 16:08:18 -0700
Subject: [PATCH] add host field support to CallInvoker

---
 src/compiler/csharp_generator.cc           | 10 ++++----
 src/csharp/Grpc.Core/CallInvoker.cs        | 10 ++++----
 src/csharp/Grpc.Core/ClientBase.cs         | 10 ++++----
 src/csharp/Grpc.Core/DefaultCallInvoker.cs | 29 +++++++++-------------
 4 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/src/compiler/csharp_generator.cc b/src/compiler/csharp_generator.cc
index bc40880e5c..4a96a909de 100644
--- a/src/compiler/csharp_generator.cc
+++ b/src/compiler/csharp_generator.cc
@@ -388,7 +388,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) {
           GetClassName(method->output_type()));
       out->Print("{\n");
       out->Indent();
-      out->Print("return CallInvoker.BlockingUnaryCall($methodfield$, options, request);\n",
+      out->Print("return CallInvoker.BlockingUnaryCall($methodfield$, null, options, request);\n",
                  "methodfield", GetMethodFieldName(method));
       out->Outdent();
       out->Print("}\n");
@@ -422,20 +422,20 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) {
     out->Indent();
     switch (GetMethodType(method)) {
       case METHODTYPE_NO_STREAMING:
-        out->Print("return CallInvoker.AsyncUnaryCall($methodfield$, options, request);\n",
+        out->Print("return CallInvoker.AsyncUnaryCall($methodfield$, null, options, request);\n",
                    "methodfield", GetMethodFieldName(method));
         break;
       case METHODTYPE_CLIENT_STREAMING:
-        out->Print("return CallInvoker.AsyncClientStreamingCall($methodfield$, options);\n",
+        out->Print("return CallInvoker.AsyncClientStreamingCall($methodfield$, null, options);\n",
                    "methodfield", GetMethodFieldName(method));
         break;
       case METHODTYPE_SERVER_STREAMING:
         out->Print(
-            "return CallInvoker.AsyncServerStreamingCall($methodfield$, options, request);\n",
+            "return CallInvoker.AsyncServerStreamingCall($methodfield$, null, options, request);\n",
             "methodfield", GetMethodFieldName(method));
         break;
       case METHODTYPE_BIDI_STREAMING:
-        out->Print("return CallInvoker.AsyncDuplexStreamingCall($methodfield$, options);\n",
+        out->Print("return CallInvoker.AsyncDuplexStreamingCall($methodfield$, null, options);\n",
                    "methodfield", GetMethodFieldName(method));
         break;
       default:
diff --git a/src/csharp/Grpc.Core/CallInvoker.cs b/src/csharp/Grpc.Core/CallInvoker.cs
index e8e43968f8..cec5255692 100644
--- a/src/csharp/Grpc.Core/CallInvoker.cs
+++ b/src/csharp/Grpc.Core/CallInvoker.cs
@@ -45,14 +45,14 @@ namespace Grpc.Core
         /// <summary>
         /// Invokes a simple remote call in a blocking fashion.
         /// </summary>
-        public abstract TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options, TRequest request)
+        public abstract TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
             where TRequest : class
             where TResponse : class;
 
         /// <summary>
         /// Invokes a simple remote call asynchronously.
         /// </summary>
-        public abstract AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options, TRequest request)
+        public abstract AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
             where TRequest : class
             where TResponse : class;
 
@@ -60,7 +60,7 @@ namespace Grpc.Core
         /// Invokes a server streaming call asynchronously.
         /// In server streaming scenario, client sends on request and server responds with a stream of responses.
         /// </summary>
-        public abstract AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options, TRequest request)
+        public abstract AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
             where TRequest : class
             where TResponse : class;
 
@@ -68,7 +68,7 @@ namespace Grpc.Core
         /// Invokes a client streaming call asynchronously.
         /// In client streaming scenario, client sends a stream of requests and server responds with a single response.
         /// </summary>
-        public abstract AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options)
+        public abstract AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
             where TRequest : class
             where TResponse : class;
 
@@ -77,7 +77,7 @@ namespace Grpc.Core
         /// In duplex streaming scenario, client sends a stream of requests and server responds with a stream of responses.
         /// The response stream is completely independent and both side can be sending messages at the same time.
         /// </summary>
-        public abstract AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options)
+        public abstract AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
             where TRequest : class
             where TResponse : class;
     }
diff --git a/src/csharp/Grpc.Core/ClientBase.cs b/src/csharp/Grpc.Core/ClientBase.cs
index f5d6ae744f..9f3c4a5327 100644
--- a/src/csharp/Grpc.Core/ClientBase.cs
+++ b/src/csharp/Grpc.Core/ClientBase.cs
@@ -124,11 +124,11 @@ namespace Grpc.Core
         /// By default, this will be set to <c>null</c> with the meaning
         /// "use default host".
         /// </summary>
-        public string Host
-        {
-            get;
-            set;
-        }
+        //public string Host
+        //{
+        //    get;
+        //    set;
+        //}
 
         /// <summary>
         /// Creates a new call to given method.
diff --git a/src/csharp/Grpc.Core/DefaultCallInvoker.cs b/src/csharp/Grpc.Core/DefaultCallInvoker.cs
index 8b77651c0c..5329478a15 100644
--- a/src/csharp/Grpc.Core/DefaultCallInvoker.cs
+++ b/src/csharp/Grpc.Core/DefaultCallInvoker.cs
@@ -56,18 +56,18 @@ namespace Grpc.Core
         /// <summary>
         /// Invokes a simple remote call in a blocking fashion.
         /// </summary>
-        public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options, TRequest request)
+        public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
         {
-            var call = CreateCall(method, options);
+            var call = CreateCall(method, host, options);
             return Calls.BlockingUnaryCall(call, request);
         }
 
         /// <summary>
         /// Invokes a simple remote call asynchronously.
         /// </summary>
-        public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options, TRequest request)
+        public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
         {
-            var call = CreateCall(method, options);
+            var call = CreateCall(method, host, options);
             return Calls.AsyncUnaryCall(call, request);
         }
 
@@ -75,9 +75,9 @@ namespace Grpc.Core
         /// Invokes a server streaming call asynchronously.
         /// In server streaming scenario, client sends on request and server responds with a stream of responses.
         /// </summary>
-        public override  AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options, TRequest request)
+        public override  AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
         {
-            var call = CreateCall(method, options);
+            var call = CreateCall(method, host, options);
             return Calls.AsyncServerStreamingCall(call, request);
         }
 
@@ -85,9 +85,9 @@ namespace Grpc.Core
         /// Invokes a client streaming call asynchronously.
         /// In client streaming scenario, client sends a stream of requests and server responds with a single response.
         /// </summary>
-        public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options)
+        public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
         {
-            var call = CreateCall(method, options);
+            var call = CreateCall(method, host, options);
             return Calls.AsyncClientStreamingCall(call);
         }
 
@@ -96,22 +96,17 @@ namespace Grpc.Core
         /// In duplex streaming scenario, client sends a stream of requests and server responds with a stream of responses.
         /// The response stream is completely independent and both side can be sending messages at the same time.
         /// </summary>
-        public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options)
+        public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
         {
-            var call = CreateCall(method, options);
+            var call = CreateCall(method, host, options);
             return Calls.AsyncDuplexStreamingCall(call);
         }
 
-        protected virtual string Host
-        {
-            get { return null; }
-        }
-
-        protected virtual CallInvocationDetails<TRequest, TResponse> CreateCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options)
+        protected virtual CallInvocationDetails<TRequest, TResponse> CreateCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
                 where TRequest : class
                 where TResponse : class
         {
-            return new CallInvocationDetails<TRequest, TResponse>(channel, method, Host, options);
+            return new CallInvocationDetails<TRequest, TResponse>(channel, method, host, options);
         }
     }
 }
-- 
GitLab