Browse Source

commit: fix null reference 2

HOME 4 years ago
parent
commit
88b95e21bd
1 changed files with 10 additions and 2 deletions
  1. 10 2
      Rac.Core/Models/Response.cs

+ 10 - 2
Rac.Core/Models/Response.cs

@@ -58,12 +58,20 @@ namespace Rac.Models
 
         public bool GetCss(out string css)
         {
-            var ct = new ContentType(ContentType);
+            var contentType = ContentType;
+            if (null == contentType)
+            {
+                css = null;
+                return false;
+            }
+
+            var ct = new ContentType(contentType);
             if (ct.MediaType != "text/css")
             {
                 css = null;
                 return false;
             }
+
             var enc = Encoding.GetEncoding(ct.CharSet ?? "utf-8");
             css = enc.GetString(Body);
             return true;
@@ -80,4 +88,4 @@ namespace Rac.Models
             return true;
         }
     }
-}
+}