@@ -39,7 +39,7 @@ public class ApiClient
39
39
/// Values for the default headers
40
40
/// </summary>
41
41
private const string CACHE_CONTROL_NONE = "no-cache" ;
42
- private const string USER_AGENT_BUNQ = "bunq-sdk-csharp/0.9.2 .0-beta" ;
42
+ private const string USER_AGENT_BUNQ = "bunq-sdk-csharp/0.10.0 .0-beta" ;
43
43
private const string LANGUAGE_EN_US = "en_US" ;
44
44
private const string REGION_NL_NL = "nl_NL" ;
45
45
private const string GEOLOCATION_ZERO = "0 0 0 0 NL" ;
@@ -49,15 +49,42 @@ public class ApiClient
49
49
/// </summary>
50
50
private const string DELIMITER_HEADER_VALUE = "," ;
51
51
52
- private static HttpClient client ;
52
+ private readonly HttpClient client ;
53
53
54
54
private readonly ApiContext apiContext ;
55
55
56
56
public ApiClient ( ApiContext apiContext )
57
57
{
58
58
this . apiContext = apiContext ;
59
+ client = CreateHttpClient ( ) ;
59
60
}
60
61
62
+ private HttpClient CreateHttpClient ( )
63
+ {
64
+ return new HttpClient ( CreateHttpClientHandler ( ) )
65
+ {
66
+ BaseAddress = new Uri ( apiContext . GetBaseUri ( ) )
67
+ } ;
68
+ }
69
+
70
+ private HttpClientHandler CreateHttpClientHandler ( )
71
+ {
72
+ // TODO: Add HTTP Public Key Pinning. It is needed to prevent possible man-in-the-middle attacks using
73
+ // the fake (or mis-issued) certificates.
74
+ // More info: https://timtaubert.de/blog/2014/10/http-public-key-pinning-explained/
75
+ // Simply put, we reduce the amount of certificates which are accepted in bunq API responses.
76
+ var handler = new HttpClientHandler ( ) ;
77
+
78
+ if ( apiContext . Proxy != null )
79
+ {
80
+ handler . Proxy = new BunqProxy ( apiContext . Proxy ) ;
81
+ handler . UseProxy = true ;
82
+ }
83
+
84
+ return handler ;
85
+ }
86
+
87
+
61
88
/// <summary>
62
89
/// Executes a POST request and returns the resulting HTTP response message.
63
90
/// </summary>
@@ -90,7 +117,6 @@ private BunqResponseRaw SendRequest(HttpRequestMessage requestMessage,
90
117
SetDefaultHeaders ( requestMessage ) ;
91
118
SetHeaders ( requestMessage , customHeaders ) ;
92
119
SetSessionHeaders ( requestMessage ) ;
93
- InitializeHttpClientIfNeeded ( apiContext ) ;
94
120
var responseMessage = client . SendAsync ( requestMessage ) . Result ;
95
121
AssertResponseSuccess ( responseMessage ) ;
96
122
ValidateResponse ( responseMessage ) ;
@@ -194,21 +220,6 @@ private string GenerateSignature(HttpRequestMessage requestMessage)
194
220
return SecurityUtils . GenerateSignature ( requestMessage , apiContext . InstallationContext . KeyPairClient ) ;
195
221
}
196
222
197
- private static void InitializeHttpClientIfNeeded ( ApiContext apiContext )
198
- {
199
- if ( client == null )
200
- {
201
- // TODO: Add HTTP Public Key Pinning. It is needed to prevent possible man-in-the-middle attacks using
202
- // the fake (or mis-issued) certificates.
203
- // More info: https://timtaubert.de/blog/2014/10/http-public-key-pinning-explained/
204
- // Simply put, we reduce the amount of certificates which are accepted in bunq API responses.
205
- client = new HttpClient
206
- {
207
- BaseAddress = new Uri ( apiContext . GetBaseUri ( ) )
208
- } ;
209
- }
210
- }
211
-
212
223
private static void AssertResponseSuccess ( HttpResponseMessage responseMessage )
213
224
{
214
225
if ( responseMessage . IsSuccessStatusCode ) return ;
0 commit comments