Skip to content

Commit 04a4b1a

Browse files
authored
Merge pull request #308 from watson-developer-cloud/validate-icp
Disable SSL
2 parents b9d8f84 + fc07483 commit 04a4b1a

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

src/IBM.WatsonDeveloperCloud/Http/WatsonHttpClient.cs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,7 @@ public class WatsonHttpClient : IClient
3939

4040
public WatsonHttpClient(string baseUri)
4141
{
42-
if (Insecure)
43-
{
44-
var httpClientHandler = new HttpClientHandler();
45-
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
46-
this.BaseClient = new HttpClient(httpClientHandler);
47-
}
48-
else
49-
{
50-
this.BaseClient = new HttpClient();
51-
}
42+
this.BaseClient = new HttpClient();
5243
this.Filters = new List<IHttpFilter> { new ErrorFilter() };
5344
if (baseUri != null)
5445
this.BaseClient.BaseAddress = new Uri(baseUri);
@@ -58,16 +49,7 @@ public WatsonHttpClient(string baseUri)
5849

5950
public WatsonHttpClient(string baseUri, string userName, string password)
6051
{
61-
if (Insecure)
62-
{
63-
var httpClientHandler = new HttpClientHandler();
64-
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
65-
this.BaseClient = new HttpClient(httpClientHandler);
66-
}
67-
else
68-
{
69-
this.BaseClient = new HttpClient();
70-
}
52+
this.BaseClient = new HttpClient();
7153
this.Filters = new List<IHttpFilter> { new ErrorFilter() };
7254
if (baseUri != null)
7355
this.BaseClient.BaseAddress = new Uri(baseUri);
@@ -77,16 +59,7 @@ public WatsonHttpClient(string baseUri, string userName, string password)
7759

7860
public WatsonHttpClient(string baseUri, string userName, string password, HttpClient client)
7961
{
80-
if (Insecure)
81-
{
82-
var httpClientHandler = new HttpClientHandler();
83-
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
84-
this.BaseClient = new HttpClient(httpClientHandler);
85-
}
86-
else
87-
{
88-
this.BaseClient = new HttpClient();
89-
}
62+
this.BaseClient = new HttpClient();
9063
this.Filters = new List<IHttpFilter> { new ErrorFilter() };
9164
if (baseUri != null)
9265
this.BaseClient.BaseAddress = new Uri(baseUri);
@@ -110,7 +83,7 @@ public IClient WithAuthentication(string userName, string password)
11083

11184
public IClient WithAuthentication(string apikey)
11285
{
113-
if(!string.IsNullOrEmpty(apikey))
86+
if (!string.IsNullOrEmpty(apikey))
11487
{
11588
this.BaseClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apikey);
11689
}
@@ -193,7 +166,16 @@ protected virtual void Dispose(bool isDisposing)
193166

194167
public void SendAsInsecure(bool insecure)
195168
{
196-
Insecure = insecure;
169+
if (insecure)
170+
{
171+
var httpClientHandler = new HttpClientHandler();
172+
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
173+
this.BaseClient = new HttpClient(httpClientHandler);
174+
}
175+
else
176+
{
177+
this.BaseClient = new HttpClient();
178+
}
197179
}
198180
}
199181
}

0 commit comments

Comments
 (0)