@@ -270,13 +270,16 @@ private RestRequest PrepareRestRequest(
270270 }
271271
272272 RestRequest requestT = new RestRequest ( path ) ;
273- RestClient . Options . UserAgent = Configuration . UserAgent ;
273+ RestClientOptions clientOptions = RestClient . Options ;
274274
275275 if ( Configuration . Proxy != null )
276276 {
277- RestClient . Options . Proxy = Configuration . Proxy ;
277+ clientOptions . Proxy = Configuration . Proxy ;
278278 }
279279
280+ RestClient = new RestClient ( clientOptions ) ;
281+ RestClient . Options . UserAgent = Configuration . UserAgent ;
282+
280283 // Add Header Parameter, if any
281284 // Passed to this function
282285 foreach ( var param in headerParams )
@@ -442,14 +445,13 @@ public object CallApi(
442445
443446 // set timeout
444447 request . Timeout = Configuration . Timeout ;
445- // set user agent
446- RestClient . Options . UserAgent = Configuration . UserAgent ;
448+ RestClientOptions clientOptions = RestClient . Options ;
447449
448450 // RestClient.ClearHandlers();
449451
450452 if ( Configuration . Proxy != null )
451453 {
452- RestClient . Options . Proxy = Configuration . Proxy ;
454+ clientOptions . Proxy = Configuration . Proxy ;
453455 }
454456
455457 // Adding Client Cert
@@ -467,9 +469,12 @@ public object CallApi(
467469 // Importing Certificates
468470 var certificate = new X509Certificate2 ( fileName , clientCertPassword ) ;
469471 clientCertPassword . Dispose ( ) ;
470- RestClient . Options . ClientCertificates = new X509CertificateCollection { certificate } ;
472+ clientOptions . ClientCertificates = new X509CertificateCollection { certificate } ;
471473 }
472474
475+ RestClient = new RestClient ( clientOptions ) ;
476+ RestClient . Options . UserAgent = Configuration . UserAgent ;
477+
473478 // Logging Request Headers
474479 var headerPrintOutput = new StringBuilder ( ) ;
475480 foreach ( var param in request . Parameters )
@@ -570,7 +575,7 @@ public async System.Threading.Tasks.Task<object> CallApiAsync(
570575 // set timeout
571576 request . Timeout = Configuration . Timeout ;
572577 // set user agent
573- RestClient . Options . UserAgent = Configuration . UserAgent ;
578+ RestClientOptions clientOptions = RestClient . Options ;
574579
575580 if ( logUtility . IsMaskingEnabled ( logger ) )
576581 {
@@ -581,6 +586,9 @@ public async System.Threading.Tasks.Task<object> CallApiAsync(
581586 logger . Debug ( $ "HTTP Request Headers :\n { headerPrintOutput . ToString ( ) } ") ;
582587 }
583588
589+ RestClient = new RestClient ( clientOptions ) ;
590+ RestClient . Options . UserAgent = Configuration . UserAgent ;
591+
584592 InterceptRequest ( request ) ;
585593 var response = await RestClient . ExecuteAsync ( request ) ;
586594 InterceptResponse ( request , response ) ;
@@ -991,10 +999,13 @@ public void CallAuthenticationHeaders(string requestType, string requestTarget,
991999 RestClient = new RestClient ( "https://" + merchantConfig . HostName ) ;
9921000 }
9931001
1002+ RestClientOptions clientOptions = RestClient . Options ;
9941003 if ( Configuration . Proxy != null )
9951004 {
996- RestClient . Options . Proxy = Configuration . Proxy ;
1005+ clientOptions . Proxy = Configuration . Proxy ;
9971006 }
1007+
1008+ RestClient = new RestClient ( clientOptions ) ;
9981009 }
9991010 }
10001011}
0 commit comments