@@ -38,12 +38,10 @@ public class RestClientFactory
3838 {
3939 private static readonly ConcurrentDictionary < int , Lazy < RestClient > > _restClientInstances = new ConcurrentDictionary < int , Lazy < RestClient > > ( ) ;
4040
41- public static RestClient GetRestClient ( Configuration configuration , RestClientOptions clientOptions )
41+ public static RestClient GetRestClient ( MerchantConfig merchantConfig , RestClientOptions clientOptions )
4242 {
43- if ( configuration . MerchantConfigDictionaryObj != null )
43+ if ( merchantConfig != null )
4444 {
45- var merchantConfig = new MerchantConfig ( configuration . MerchantConfigDictionaryObj ) ;
46-
4745 ServicePointManager . DefaultConnectionLimit = int . Parse ( merchantConfig . MaxConnectionPoolSize ) ;
4846 ServicePointManager . MaxServicePointIdleTime = int . Parse ( merchantConfig . KeepAliveTime ) ;
4947 }
@@ -344,11 +342,13 @@ public object CallApi(
344342 path , method , queryParams , postBody , headerParams , formParams , fileParams ,
345343 pathParams , contentType ) ;
346344
347- var newRestClientOptions = GetRestClientOptions ( Configuration ) ;
345+ MerchantConfig merchantConfig = new MerchantConfig ( merchantConfigDictionary : Configuration . MerchantConfigDictionaryObj , mapToControlMLEonAPI : Configuration . MapToControlMLEonAPI ) ;
346+
347+ var newRestClientOptions = GetRestClientOptions ( merchantConfig , Configuration . UserAgent , TimeSpan . FromMilliseconds ( Configuration . Timeout ) ) ;
348348
349349 // RestClient.ClearHandlers();
350350
351- var actualRestClient = RestClientFactory . GetRestClient ( Configuration , newRestClientOptions ) ;
351+ var actualRestClient = RestClientFactory . GetRestClient ( merchantConfig , newRestClientOptions ) ;
352352
353353 // Logging Request Headers
354354 var headerPrintOutput = new StringBuilder ( ) ;
@@ -391,18 +391,16 @@ public object CallApi(
391391 return response ;
392392 }
393393
394- private RestClientOptions GetRestClientOptions ( Configuration configuration )
394+ private RestClientOptions GetRestClientOptions ( MerchantConfig merchantConfig , string userAgent , TimeSpan timeout )
395395 {
396396 RestClientOptions clientOptions = new RestClientOptions ( ) ;
397397
398- clientOptions . UserAgent = configuration . UserAgent ;
399- clientOptions . Timeout = TimeSpan . FromMilliseconds ( configuration . Timeout ) ;
398+ clientOptions . UserAgent = userAgent ;
399+ clientOptions . Timeout = timeout ;
400400
401- var merchantConfig = configuration . MerchantConfigDictionaryObj != null
402- ? new MerchantConfig ( configuration . MerchantConfigDictionaryObj )
403- : new MerchantConfig ( ) ;
404-
405- if ( configuration . Proxy == null && merchantConfig . UseProxy != null )
401+ IWebProxy webProxy = null ;
402+
403+ if ( merchantConfig . UseProxy != null )
406404 {
407405 if ( bool . Parse ( merchantConfig . UseProxy ) )
408406 {
@@ -415,14 +413,14 @@ private RestClientOptions GetRestClientOptions(Configuration configuration)
415413 proxy . Credentials = new NetworkCredential ( merchantConfig . ProxyUsername , merchantConfig . ProxyPassword ) ;
416414 }
417415
418- configuration . AddWebProxy ( proxy ) ;
416+ webProxy = proxy ;
419417 }
420418 }
421419 }
422420
423- if ( configuration . Proxy != null )
421+ if ( webProxy != null )
424422 {
425- clientOptions . Proxy = configuration . Proxy ;
423+ clientOptions . Proxy = webProxy ;
426424 }
427425
428426 if ( Equals ( bool . Parse ( merchantConfig . EnableClientCert ) , true ) )
@@ -506,9 +504,11 @@ public async System.Threading.Tasks.Task<object> CallApiAsync(
506504
507505 logger . Debug ( $ "HTTP Request Headers :\n { logUtility . MaskSensitiveData ( headerPrintOutput . ToString ( ) ) } ") ;
508506
509- var newRestClientOptions = GetRestClientOptions ( Configuration ) ;
507+ MerchantConfig merchantConfig = new MerchantConfig ( merchantConfigDictionary : Configuration . MerchantConfigDictionaryObj , mapToControlMLEonAPI : Configuration . MapToControlMLEonAPI ) ;
508+
509+ var newRestClientOptions = GetRestClientOptions ( merchantConfig , Configuration . UserAgent , TimeSpan . FromMilliseconds ( Configuration . Timeout ) ) ;
510510
511- var actualRestClient = RestClientFactory . GetRestClient ( Configuration , newRestClientOptions ) ;
511+ var actualRestClient = RestClientFactory . GetRestClient ( merchantConfig , newRestClientOptions ) ;
512512
513513 InterceptRequest ( request ) ;
514514 var response = await actualRestClient . ExecuteAsync ( request ) ;
0 commit comments