@@ -257,12 +257,17 @@ private static void AddCommentToUserAgent(
257
257
return ;
258
258
}
259
259
260
- var normalizedComment = comment
261
- . Replace ( ")" , string . Empty )
262
- . Replace ( "(" , string . Empty ) ;
260
+ var normalizedComment = RemoveBracketsFrom ( comment ) ;
263
261
userAgentHeader . Add ( new ProductInfoHeaderValue ( $ "({ normalizedComment } )") ) ;
264
262
}
265
263
264
+ private static string RemoveBracketsFrom ( string comment )
265
+ {
266
+ return comment
267
+ . Replace ( ")" , string . Empty )
268
+ . Replace ( "(" , string . Empty ) ;
269
+ }
270
+
266
271
private static SortedDictionary < string , object > GetCallParams ( HttpMethod method , BaseParams parameters )
267
272
{
268
273
parameters ? . Check ( ) ;
@@ -474,7 +479,7 @@ private void PrePrepareRequestBody(
474
479
userAgentHeader . Add ( new ProductInfoHeaderValue ( "CloudinaryDotNet" , CloudinaryVersion . Full ) ) ;
475
480
476
481
AddCommentToUserAgent ( userAgentHeader , USER_AGENT ) ;
477
- AddCommentToUserAgent ( userAgentHeader , UserPlatform ) ;
482
+ SetUserPlatform ( userAgentHeader ) ;
478
483
479
484
byte [ ] authBytes = Encoding . ASCII . GetBytes ( GetApiCredentials ( ) ) ;
480
485
request . Headers . Add ( "Authorization" , string . Format ( CultureInfo . InvariantCulture , "Basic {0}" , Convert . ToBase64String ( authBytes ) ) ) ;
@@ -494,6 +499,36 @@ private void PrePrepareRequestBody(
494
499
}
495
500
}
496
501
502
+ private void SetUserPlatform ( HttpHeaderValueCollection < ProductInfoHeaderValue > userAgentHeader )
503
+ {
504
+ Console . WriteLine ( $ "UserPlatform: [{ UserPlatform } ] ======") ;
505
+ var up = UserPlatform ? . Trim ( ) ;
506
+ if ( string . IsNullOrEmpty ( up ) )
507
+ {
508
+ return ;
509
+ }
510
+
511
+ var upp = up . Split ( '/' ) ;
512
+ var productName = GetElement ( 0 ) ;
513
+ if ( string . IsNullOrEmpty ( productName ) )
514
+ {
515
+ return ;
516
+ }
517
+
518
+ var productVersion = GetElement ( 1 ) ;
519
+ if ( string . IsNullOrEmpty ( productVersion ) )
520
+ {
521
+ productVersion = "0.1" ;
522
+ }
523
+
524
+ userAgentHeader . Add ( new ProductInfoHeaderValue ( productName , productVersion ) ) ;
525
+
526
+ string GetElement ( int index )
527
+ {
528
+ return upp . ElementAtOrDefault ( index ) ? . Trim ( ) ;
529
+ }
530
+ }
531
+
497
532
private async Task PrepareRequestContentAsync (
498
533
HttpRequestMessage request ,
499
534
SortedDictionary < string , object > parameters ,
0 commit comments