@@ -31,14 +31,30 @@ namespace G42Cloud.SDK.Core
3131{
3232 public static class HttpUtils
3333 {
34+
35+ private static readonly List < string > HttpContentHeadersList = new List < string >
36+ {
37+ "Allow" ,
38+ "Content-Disposition" ,
39+ "Content-Encoding" ,
40+ "Content-Language" ,
41+ "Content-Location" ,
42+ "Content-MD5" ,
43+ "Content-Range" ,
44+ "Content-Type" ,
45+ "Content-Length" ,
46+ "Expires" ,
47+ "Last-Modified"
48+ } ;
49+
3450 public static string AddUrlPath ( string path , Dictionary < string , string > pathParams )
3551 {
3652 return pathParams . Aggregate ( path ,
3753 ( current , keyValuePair ) => current . Replace ( "{" + keyValuePair . Key + "}" ,
3854 keyValuePair . Value ) ) ;
3955 }
4056
41- private static string GetQueryParameters ( Object obj )
57+ private static string GetQueryParameters ( object obj )
4258 {
4359 var sb = new StringBuilder ( ) ;
4460 var t = obj . GetType ( ) ;
@@ -270,13 +286,18 @@ private static string GetRequestBody(object obj, string contentType)
270286 {
271287 foreach ( var elem in sdkPropertyList )
272288 {
289+ if ( elem is string eleString )
290+ {
291+ return eleString ;
292+ }
293+
273294 return contentType == "application/xml" ? XmlUtils . Serialize ( elem ) : JsonUtils . Serialize ( elem ) ;
274295 }
275296 }
276297
277298 return "" ;
278299 }
279-
300+
280301 private static Dictionary < string , object > GetFormData ( object obj )
281302 {
282303 var t = obj . GetType ( ) ;
@@ -328,14 +349,14 @@ private static Dictionary<string, object> GetFormData(object obj)
328349 }
329350
330351 return null ;
331- }
352+ }
332353
333354 public static SdkRequest InitSdkRequest ( string path , object data = null )
334355 {
335356 return InitSdkRequest ( path , null , data ) ;
336357 }
337358
338- public static SdkRequest InitSdkRequest ( string path , String contentType , object data = null )
359+ public static SdkRequest InitSdkRequest ( string path , string contentType , object data = null )
339360 {
340361 if ( path != null && string . IsNullOrEmpty ( path ) )
341362 {
@@ -352,7 +373,7 @@ public static SdkRequest InitSdkRequest(string path, String contentType, object
352373 }
353374
354375 var cname = GetCname ( data ) ;
355- if ( ! String . IsNullOrEmpty ( cname ) )
376+ if ( ! string . IsNullOrEmpty ( cname ) )
356377 {
357378 request . Cname = cname ;
358379 }
@@ -385,7 +406,7 @@ public static SdkRequest InitSdkRequest(string path, String contentType, object
385406 request . Body = bodyData ;
386407 }
387408 }
388-
409+
389410 if ( ! string . IsNullOrEmpty ( contentType ) )
390411 {
391412 request . ContentType = contentType ;
@@ -405,7 +426,7 @@ public static T DeSerializeStream<T>(HttpResponseMessage message)
405426 var t = Activator . CreateInstance < T > ( ) ;
406427 t . GetType ( ) . GetProperty ( "HttpStatusCode" ) ? . SetValue ( t , ( int ) message . StatusCode , null ) ;
407428 t . GetType ( ) . GetProperty ( "HttpHeaders" ) ? . SetValue ( t , message . Headers . ToString ( ) , null ) ;
408- BindingFlags flag = BindingFlags . Public | BindingFlags . Instance ;
429+ var flag = BindingFlags . Public | BindingFlags . Instance ;
409430 t . GetType ( ) . GetMethod ( "SetStream" )
410431 ? . Invoke ( t , flag , Type . DefaultBinder ,
411432 new object [ ]
@@ -422,21 +443,6 @@ public static void SetAdditionalAttrs<T>(HttpResponseMessage message, T obj, str
422443 obj . GetType ( ) . GetProperty ( "HttpBody" ) ? . SetValue ( obj , body , null ) ;
423444 }
424445
425- private static readonly List < string > HttpContentHeadersList = new List < string >
426- {
427- "Allow" ,
428- "Content-Disposition" ,
429- "Content-Encoding" ,
430- "Content-Language" ,
431- "Content-Location" ,
432- "Content-MD5" ,
433- "Content-Range" ,
434- "Content-Type" ,
435- "Content-Length" ,
436- "Expires" ,
437- "Last-Modified"
438- } ;
439-
440446 public static void SetResponseHeaders < T > ( HttpResponseMessage message , T obj )
441447 {
442448 const BindingFlags instanceBindFlags = BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ;
0 commit comments