@@ -257,12 +257,17 @@ private static void AddCommentToUserAgent(
257257 return ;
258258 }
259259
260- var normalizedComment = comment
261- . Replace ( ")" , string . Empty )
262- . Replace ( "(" , string . Empty ) ;
260+ var normalizedComment = RemoveBracketsFrom ( comment ) ;
263261 userAgentHeader . Add ( new ProductInfoHeaderValue ( $ "({ normalizedComment } )") ) ;
264262 }
265263
264+ private static string RemoveBracketsFrom ( string comment )
265+ {
266+ return comment
267+ . Replace ( ")" , string . Empty )
268+ . Replace ( "(" , string . Empty ) ;
269+ }
270+
266271 private static SortedDictionary < string , object > GetCallParams ( HttpMethod method , BaseParams parameters )
267272 {
268273 parameters ? . Check ( ) ;
@@ -474,7 +479,7 @@ private void PrePrepareRequestBody(
474479 userAgentHeader . Add ( new ProductInfoHeaderValue ( "CloudinaryDotNet" , CloudinaryVersion . Full ) ) ;
475480
476481 AddCommentToUserAgent ( userAgentHeader , USER_AGENT ) ;
477- AddCommentToUserAgent ( userAgentHeader , UserPlatform ) ;
482+ SetUserPlatform ( userAgentHeader ) ;
478483
479484 byte [ ] authBytes = Encoding . ASCII . GetBytes ( GetApiCredentials ( ) ) ;
480485 request . Headers . Add ( "Authorization" , string . Format ( CultureInfo . InvariantCulture , "Basic {0}" , Convert . ToBase64String ( authBytes ) ) ) ;
@@ -494,6 +499,36 @@ private void PrePrepareRequestBody(
494499 }
495500 }
496501
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+
497532 private async Task PrepareRequestContentAsync (
498533 HttpRequestMessage request ,
499534 SortedDictionary < string , object > parameters ,
0 commit comments