Repository: thrift
Updated Branches:
  refs/heads/master 37042270e -> c0ad36848


THRIFT-2455 Allow client certificates to be used with THttpClient
Client: C#
Patch: Adam Connelly & Jens Geyer

This closes #96

commit a87068655a3d31e2f85e5630462dd174b02f43c6
 Author: Adam Connelly <[email protected]>
 Date: 2014-04-09T12:06:20Z

THRIFT-2455: Allow client certificates to be used with THttpClient


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/c0ad3684
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/c0ad3684
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/c0ad3684

Branch: refs/heads/master
Commit: c0ad3684863649a02a53ec7e462af248acaf1bd7
Parents: 3704227
Author: Jens Geyer <[email protected]>
Authored: Thu May 8 22:31:34 2014 +0200
Committer: Jens Geyer <[email protected]>
Committed: Thu May 8 22:31:34 2014 +0200

----------------------------------------------------------------------
 lib/csharp/src/Transport/THttpClient.cs | 33 ++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/c0ad3684/lib/csharp/src/Transport/THttpClient.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/THttpClient.cs 
b/lib/csharp/src/Transport/THttpClient.cs
index d19b7a7..2acf468 100644
--- a/lib/csharp/src/Transport/THttpClient.cs
+++ b/lib/csharp/src/Transport/THttpClient.cs
@@ -24,32 +24,42 @@ using System.Collections.Generic;
 using System.IO;
 using System.Net;
 using System.Threading;
+using System.Linq;
+using System.Security.Cryptography.X509Certificates;
 
 namespace Thrift.Transport
 {
-       public class THttpClient : TTransport, IDisposable
-       {
-               private readonly Uri uri;
-               private Stream inputStream;
-               private MemoryStream outputStream = new MemoryStream();
+
+    public class THttpClient : TTransport, IDisposable
+    {
+        private readonly Uri uri;
+        private readonly X509Certificate[] certificates;
+        private Stream inputStream;
+        private MemoryStream outputStream = new MemoryStream();
 
         // Timeouts in milliseconds
         private int connectTimeout = 30000;
 
         private int readTimeout = 30000;
 
-               private IDictionary<String, String> customHeaders = new 
Dictionary<string, string>();
+        private IDictionary<String, String> customHeaders = new 
Dictionary<string, string>();
 
 #if !SILVERLIGHT
         private IWebProxy proxy = WebRequest.DefaultWebProxy;
 #endif
 
-        public THttpClient(Uri u)
+        public THttpClient(Uri u) 
+            : this(u, Enumerable.Empty<X509Certificate>())
                {
-                       uri = u;
                }
 
-               public int ConnectTimeout
+           public THttpClient(Uri u, IEnumerable<X509Certificate> certificates)
+           {
+               uri = u;
+            this.certificates = (certificates ?? 
Enumerable.Empty<X509Certificate>()).ToArray();
+           }
+
+        public int ConnectTimeout
                {
                        set
                        {
@@ -180,7 +190,12 @@ namespace Thrift.Transport
                {
                        HttpWebRequest connection = 
(HttpWebRequest)WebRequest.Create(uri);
 
+
 #if !SILVERLIGHT
+                       // Adding certificates through code is not supported 
with WP7 Silverlight
+                       // see "Windows Phone 7 and 
Certificates_FINAL_121610.pdf"
+                   connection.ClientCertificates.AddRange(certificates);
+
                        if (connectTimeout > 0)
                        {
                                connection.Timeout = connectTimeout;

Reply via email to