Skip to content

Commit e6a3205

Browse files
committed
Added fix for RestClient
1 parent 4f7629d commit e6a3205

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

Client/ApiClient.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

generator/cybersource-csharp-template/ApiClient.mustache

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,16 @@ namespace {{packageName}}.Client
312312
}
313313

314314
RestRequest requestT = new RestRequest(path);
315-
RestClient.Options.UserAgent = Configuration.UserAgent;
315+
RestClientOptions clientOptions = RestClient.Options;
316316

317317
if (Configuration.Proxy != null)
318318
{
319-
RestClient.Options.Proxy = Configuration.Proxy;
319+
clientOptions.Proxy = Configuration.Proxy;
320320
}
321321

322+
RestClient = new RestClient(clientOptions);
323+
RestClient.Options.UserAgent = Configuration.UserAgent;
324+
322325
// Add Header Parameter, if any
323326
// Passed to this function
324327
foreach (var param in headerParams)
@@ -484,14 +487,13 @@ namespace {{packageName}}.Client
484487

485488
// set timeout
486489
request.Timeout = Configuration.Timeout;
487-
// set user agent
488-
RestClient.Options.UserAgent = Configuration.UserAgent;
490+
RestClientOptions clientOptions = RestClient.Options;
489491

490492
// RestClient.ClearHandlers();
491493

492494
if (Configuration.Proxy != null)
493495
{
494-
RestClient.Options.Proxy = Configuration.Proxy;
496+
clientOptions.Proxy = Configuration.Proxy;
495497
}
496498

497499
// Adding Client Cert
@@ -509,9 +511,12 @@ namespace {{packageName}}.Client
509511
// Importing Certificates
510512
var certificate = new X509Certificate2(fileName, clientCertPassword);
511513
clientCertPassword.Dispose();
512-
RestClient.Options.ClientCertificates = new X509CertificateCollection { certificate };
514+
clientOptions.ClientCertificates = new X509CertificateCollection { certificate };
513515
}
514516

517+
RestClient = new RestClient(clientOptions);
518+
RestClient.Options.UserAgent = Configuration.UserAgent;
519+
515520
// Logging Request Headers
516521
var headerPrintOutput = new StringBuilder();
517522
foreach (var param in request.Parameters)
@@ -624,7 +629,7 @@ namespace {{packageName}}.Client
624629
// set timeout
625630
request.Timeout = Configuration.Timeout;
626631
// set user agent
627-
RestClient.Options.UserAgent = Configuration.UserAgent;
632+
RestClientOptions clientOptions = RestClient.Options;
628633

629634
if (logUtility.IsMaskingEnabled(logger))
630635
{
@@ -635,6 +640,9 @@ namespace {{packageName}}.Client
635640
logger.Debug($"HTTP Request Headers :\n{headerPrintOutput.ToString()}");
636641
}
637642

643+
RestClient = new RestClient(clientOptions);
644+
RestClient.Options.UserAgent = Configuration.UserAgent;
645+
638646
InterceptRequest(request);
639647
var response = await RestClient.Execute{{^netStandard}}Async{{/netStandard}}(request);
640648
InterceptResponse(request, response);
@@ -1062,10 +1070,13 @@ namespace {{packageName}}.Client
10621070
RestClient = new RestClient("https://" + merchantConfig.HostName);
10631071
}
10641072

1073+
RestClientOptions clientOptions = RestClient.Options;
10651074
if (Configuration.Proxy != null)
10661075
{
1067-
RestClient.Options.Proxy = Configuration.Proxy;
1076+
clientOptions.Proxy = Configuration.Proxy;
10681077
}
1078+
1079+
RestClient = new RestClient(clientOptions);
10691080
}
10701081
}
10711082
}

0 commit comments

Comments
 (0)