Merge pull request #3066 from alexanderkyte/pedump_sgen
[mono.git] / mcs / class / System.Net / System.Net.Policy / ClientAccessPolicy.cs
index 6cff0a06bbea1cd99320ac2e623e24156107e697..ab6af6c6d3ada59fd36d1b9fcca7f18fd15e63e1 100644 (file)
@@ -128,7 +128,6 @@ namespace System.Net.Policy {
                                        // is the application (XAP) URI allowed by the policy ?
                                        // check headers
                                        if (!af.HttpRequestHeaders.IsAllowed (headerKeys)) {
-                                               Exception = new NotSupportedException ();
                                                return false;
                                        }
 
@@ -154,7 +153,6 @@ namespace System.Net.Policy {
                        {
                                Domains = new List<string> ();
                                HttpRequestHeaders = new Headers ();
-                               Scheme = String.Empty;
                        }
 
                        public bool AllowAnyDomain { get; set; }
@@ -165,23 +163,8 @@ namespace System.Net.Policy {
 
                        public bool AllowAnyMethod { get; set; }
 
-                       public string Scheme { get; internal set; }
-
                        public bool IsAllowed (Uri uri, string method)
                        {
-                               // check scheme
-                               if ((Scheme.Length > 0) && (Scheme == uri.Scheme)) {
-                                       switch (Scheme) {
-                                       case "http":
-                                               return (uri.Port == 80);
-                                       case "https":
-                                               return (uri.Port == 443);
-                                       case "file":
-                                               return true;
-                                       default:
-                                               return false;
-                                       }
-                               }
                                // check methods
                                if (!AllowAnyMethod) {
                                        // if not all methods are allowed (*) then only GET and POST request are possible
@@ -196,12 +179,16 @@ namespace System.Net.Policy {
                                if (AllowAnyDomain)
                                        return true;
 
-                               if (Domains.All (domain => !CheckDomainUri (domain)))
+                               if (Domains.All (domain => !CheckDomainUri (uri, domain)))
                                        return false;
                                return true;
                        }
 
-                       static bool CheckDomainUri (string policy)
+                       const string AllHttpScheme = "http://*";
+                       const string AllHttpsScheme = "https://*";
+                       const string AllFileScheme = "file:///";
+
+                       static bool CheckDomainUri (Uri applicationUri, string policy)
                        {
                                Uri uri;
                                if (Uri.TryCreate (policy, UriKind.Absolute, out uri)) {
@@ -219,7 +206,22 @@ namespace System.Net.Policy {
                                // check for matching protocol
                                if (!policy.StartsWith (ApplicationUri.Scheme))
                                        return false;
-                               // check for the wirld card immediately after the scheme
+
+                               switch (ApplicationUri.Scheme) {
+                               case "http":
+                                       if (policy == AllHttpScheme)
+                                               return (applicationUri.Port == 80);
+                                       break;
+                               case "https":
+                                       if (policy == AllHttpsScheme)
+                                               return (applicationUri.Port == 443);
+                                       break;
+                               case "file":
+                                       if (policy == AllFileScheme)
+                                               return true;
+                                       break;
+                               }
+
                                if (policy.IndexOf ("://*.", ApplicationUri.Scheme.Length) != ApplicationUri.Scheme.Length)
                                        return false;
                                // remove *. from uri