Skip to content

Commit 76f314a

Browse files
committed
Expose proxy
1 parent c8b2a2d commit 76f314a

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

ExchangeSharp/API/Common/APIRequestMaker.cs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT LICENSE
33
44
Copyright 2017 Digital Ruby, LLC - http://www.digitalruby.com
@@ -26,22 +26,32 @@ public sealed class APIRequestMaker : IAPIRequestMaker
2626
{
2727
private readonly IAPIRequestHandler api;
2828

29-
internal class InternalHttpWebRequest : IHttpWebRequest
29+
/// <summary>
30+
/// Proxy for http requests, reads from HTTP_PROXY environment var by default
31+
/// You can also set via code if you like
32+
/// </summary>
33+
public static WebProxy? Proxy { get; set; }
34+
35+
/// <summary>
36+
/// Static constructor
37+
/// </summary>
38+
static APIRequestMaker()
39+
{
40+
var httpProxy = Environment.GetEnvironmentVariable("http_proxy");
41+
httpProxy ??= Environment.GetEnvironmentVariable("HTTP_PROXY");
42+
43+
if (string.IsNullOrWhiteSpace(httpProxy))
44+
{
45+
return;
46+
}
47+
48+
var uri = new Uri(httpProxy);
49+
Proxy = new WebProxy(uri);
50+
51+
}
52+
internal class InternalHttpWebRequest : IHttpWebRequest
3053
{
3154
internal readonly HttpWebRequest Request;
32-
internal static WebProxy Proxy;
33-
34-
static InternalHttpWebRequest()
35-
{
36-
var httpProxy = Environment.GetEnvironmentVariable("http_proxy");
37-
httpProxy ??= Environment.GetEnvironmentVariable("HTTP_PROXY");
38-
39-
if (string.IsNullOrEmpty(httpProxy))
40-
return;
41-
42-
var uri = new Uri(httpProxy);
43-
Proxy = new WebProxy(uri);
44-
}
4555

4656
public InternalHttpWebRequest(Uri fullUri)
4757
{

ExchangeSharp/Utility/ClientWebSocket.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT LICENSE
33
44
Copyright 2017 Digital Ruby, LLC - http://www.digitalruby.com
@@ -91,7 +91,10 @@ private class ClientWebSocketImplementation : IClientWebSocketImplementation
9191
{
9292
private readonly System.Net.WebSockets.ClientWebSocket webSocket = new System.Net.WebSockets.ClientWebSocket()
9393
{
94-
Options = { Proxy = APIRequestMaker.InternalHttpWebRequest.Proxy }
94+
Options =
95+
{
96+
Proxy = APIRequestMaker.Proxy
97+
}
9598
};
9699

97100
public WebSocketState State

0 commit comments

Comments
 (0)