Skip to content

Commit 956acc8

Browse files
author
mwatson
committed
Add proxy back in
1 parent 54878bd commit 956acc8

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

Src/StackifyLib/Utils/HttpClient.cs

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class AppIdentityInfo
2828

2929
public class HttpClient
3030
{
31-
// public static IWebProxy CustomWebProxy = null;
31+
public static IWebProxy CustomWebProxy = null;
3232

3333
public string BaseAPIUrl { get; private set; }
3434

@@ -74,7 +74,9 @@ public class StackifyWebResponse
7474

7575
static HttpClient()
7676
{
77-
//LoadWebProxyConfig();
77+
#if NET45 || NET40
78+
LoadWebProxyConfig();
79+
#endif
7880
}
7981

8082
public HttpClient(string apiKey, string apiUrl)
@@ -110,49 +112,50 @@ public HttpClient(string apiKey, string apiUrl)
110112
BaseAPIUrl += "/";
111113
}
112114

113-
// public static void LoadWebProxyConfig()
114-
// {
115-
// try
116-
// {
117-
//string val = Config.Get("Stackify.ProxyServer");
118-
119-
// if (!string.IsNullOrEmpty(val))
120-
// {
115+
#if NET45 || NET40
116+
public static void LoadWebProxyConfig()
117+
{
118+
try
119+
{
120+
string val = Config.Get("Stackify.ProxyServer");
121121

122-
// StackifyAPILogger.Log("Setting proxy server based on override config", true);
122+
if (!string.IsNullOrEmpty(val))
123+
{
123124

124-
// var uri = new Uri(val);
125+
StackifyAPILogger.Log("Setting proxy server based on override config", true);
125126

126-
// var proxy = new WebProxy(uri, false);
127+
var uri = new Uri(val);
127128

128-
// if (!string.IsNullOrEmpty(uri.UserInfo) && uri.UserInfo.Contains(":"))
129-
// {
130-
// string[] pieces = uri.UserInfo.Split(':');
129+
var proxy = new WebProxy(uri, false);
131130

132-
// proxy.Credentials = new NetworkCredential(pieces[0], pieces[1]);
133-
// }
134-
// else
135-
// {
131+
if (!string.IsNullOrEmpty(uri.UserInfo) && uri.UserInfo.Contains(":"))
132+
{
133+
string[] pieces = uri.UserInfo.Split(':');
136134

137-
// string settingUseDefault = Config.Get("Stackify.ProxyUseDefaultCredentials");
135+
proxy.Credentials = new NetworkCredential(pieces[0], pieces[1]);
136+
}
137+
else
138+
{
138139

139-
// bool useDefault;
140+
string settingUseDefault = Config.Get("Stackify.ProxyUseDefaultCredentials");
140141

141-
// if (!string.IsNullOrEmpty(settingUseDefault) && bool.TryParse(settingUseDefault, out useDefault))
142-
// {
143-
// //will make it use the user of the running windows service
144-
// proxy.UseDefaultCredentials = useDefault;
145-
// }
146-
// }
147-
// CustomWebProxy = proxy;
148-
// }
149-
// }
150-
// catch (Exception ex)
151-
// {
152-
// StackifyAPILogger.Log("Error setting default web proxy " + ex.Message, true);
153-
// }
154-
// }
142+
bool useDefault;
155143

144+
if (!string.IsNullOrEmpty(settingUseDefault) && bool.TryParse(settingUseDefault, out useDefault))
145+
{
146+
//will make it use the user of the running windows service
147+
proxy.UseDefaultCredentials = useDefault;
148+
}
149+
}
150+
CustomWebProxy = proxy;
151+
}
152+
}
153+
catch (Exception ex)
154+
{
155+
StackifyAPILogger.Log("Error setting default web proxy " + ex.Message, true);
156+
}
157+
}
158+
#endif
156159

157160
/// <summary>
158161
/// This method does some throttling when errors happen to control when it should try again. Error backoff logic
@@ -582,7 +585,7 @@ private HttpWebRequest BuildJsonRequest(string url, string jsonData, bool compre
582585

583586
request.Headers["X-Stackify-Key"] = this.APIKey;
584587
request.ContentType = "application/json";
585-
request.Headers[HttpRequestHeader.UserAgent] = "StackifyLibCore-" + _version;
588+
request.Headers[HttpRequestHeader.UserAgent] = "StackifyLib-" + _version;
586589

587590
//if (HttpClient.CustomWebProxy != null)
588591
//{

0 commit comments

Comments
 (0)