@@ -39,15 +39,13 @@ public class RestClientFactory
3939 {
4040 private static readonly ConcurrentDictionary < int , Lazy < RestClient > > _restClientInstances = new ConcurrentDictionary < int , Lazy < RestClient > > ( ) ;
4141
42- public static RestClient GetRestClient ( Configuration configuration , RestClientOptions clientOptions )
42+ public static RestClient GetRestClient ( MerchantConfig merchantConfig , RestClientOptions clientOptions )
4343 {
4444 int MaxServicePointIdleTime ;
4545 int DefaultConnectionLimit ;
4646
47- if ( configuration . MerchantConfigDictionaryObj != null )
47+ if ( merchantConfig != null )
4848 {
49- var merchantConfig = new MerchantConfig ( configuration . MerchantConfigDictionaryObj ) ;
50-
5149 DefaultConnectionLimit = int . Parse ( merchantConfig . MaxConnectionPoolSize ) ;
5250 MaxServicePointIdleTime = int . Parse ( merchantConfig . KeepAliveTime ) ;
5351 }
@@ -64,6 +62,7 @@ public static RestClient GetRestClient(Configuration configuration, RestClientOp
6462 } ;
6563
6664 var httpClient = new HttpClient ( handler ) ;
65+ httpClient . Timeout = TimeSpan . FromMilliseconds ( int . Parse ( merchantConfig . TimeOut ) ) ;
6766
6867 int hash = GetHashOfRestClientOptions ( clientOptions ) ;
6968
@@ -356,11 +355,13 @@ public object CallApi(
356355 path , method , queryParams , postBody , headerParams , formParams , fileParams ,
357356 pathParams , contentType ) ;
358357
359- var newRestClientOptions = GetRestClientOptions ( Configuration ) ;
358+ MerchantConfig merchantConfig = new MerchantConfig ( merchantConfigDictionary : Configuration . MerchantConfigDictionaryObj , mapToControlMLEonAPI : Configuration . MapToControlMLEonAPI ) ;
359+
360+ var newRestClientOptions = GetRestClientOptions ( merchantConfig , Configuration . UserAgent , TimeSpan . FromMilliseconds ( Configuration . Timeout ) ) ;
360361
361362 // RestClient.ClearHandlers();
362363
363- var actualRestClient = RestClientFactory . GetRestClient ( Configuration , newRestClientOptions ) ;
364+ var actualRestClient = RestClientFactory . GetRestClient ( merchantConfig , newRestClientOptions ) ;
364365
365366 // Logging Request Headers
366367 var headerPrintOutput = new StringBuilder ( ) ;
@@ -403,18 +404,16 @@ public object CallApi(
403404 return response ;
404405 }
405406
406- private RestClientOptions GetRestClientOptions ( Configuration configuration )
407+ private RestClientOptions GetRestClientOptions ( MerchantConfig merchantConfig , string userAgent , TimeSpan timeout )
407408 {
408409 RestClientOptions clientOptions = new RestClientOptions ( ) ;
409410
410- clientOptions . UserAgent = configuration . UserAgent ;
411- clientOptions . Timeout = TimeSpan . FromMilliseconds ( configuration . Timeout ) ;
411+ clientOptions . UserAgent = userAgent ;
412+ clientOptions . Timeout = timeout ;
412413
413- var merchantConfig = configuration . MerchantConfigDictionaryObj != null
414- ? new MerchantConfig ( configuration . MerchantConfigDictionaryObj )
415- : new MerchantConfig ( ) ;
414+ IWebProxy webProxy = null ;
416415
417- if ( configuration . Proxy == null && merchantConfig . UseProxy != null )
416+ if ( merchantConfig . UseProxy != null )
418417 {
419418 if ( bool . Parse ( merchantConfig . UseProxy ) )
420419 {
@@ -427,14 +426,14 @@ private RestClientOptions GetRestClientOptions(Configuration configuration)
427426 proxy . Credentials = new NetworkCredential ( merchantConfig . ProxyUsername , merchantConfig . ProxyPassword ) ;
428427 }
429428
430- configuration . AddWebProxy ( proxy ) ;
429+ webProxy = proxy ;
431430 }
432431 }
433432 }
434433
435- if ( configuration . Proxy != null )
434+ if ( webProxy != null )
436435 {
437- clientOptions . Proxy = configuration . Proxy ;
436+ clientOptions . Proxy = webProxy ;
438437 }
439438
440439 if ( Equals ( bool . Parse ( merchantConfig . EnableClientCert ) , true ) )
@@ -518,9 +517,11 @@ public async System.Threading.Tasks.Task<object> CallApiAsync(
518517
519518 logger . Debug ( $ "HTTP Request Headers :\n { logUtility . MaskSensitiveData ( headerPrintOutput . ToString ( ) ) } ") ;
520519
521- var newRestClientOptions = GetRestClientOptions ( Configuration ) ;
520+ MerchantConfig merchantConfig = new MerchantConfig ( merchantConfigDictionary : Configuration . MerchantConfigDictionaryObj , mapToControlMLEonAPI : Configuration . MapToControlMLEonAPI ) ;
521+
522+ var newRestClientOptions = GetRestClientOptions ( merchantConfig , Configuration . UserAgent , TimeSpan . FromMilliseconds ( Configuration . Timeout ) ) ;
522523
523- var actualRestClient = RestClientFactory . GetRestClient ( Configuration , newRestClientOptions ) ;
524+ var actualRestClient = RestClientFactory . GetRestClient ( merchantConfig , newRestClientOptions ) ;
524525
525526 InterceptRequest ( request ) ;
526527 var response = await actualRestClient . ExecuteAsync ( request ) ;
0 commit comments