Browse Source

Make "https" scheme only when Transport security mode is ON

The behavior of the WebHttpBinding in case of SecurityMode ==
WebHttpSecurityMode.TransportCredentialOnly must use the http scheme, in
order to allow authentication of the client based on the standard HTTP
headers, like WWW-Authenticate: Scheme realm="" and so on. This behavior
is the default in .net;
stukselbax 10 years ago
parent
commit
fccd4b01a7

+ 1 - 1
mcs/class/System.ServiceModel.Web/System.ServiceModel/WebHttpBinding.cs

@@ -158,7 +158,7 @@ namespace System.ServiceModel
 		}
 
 		public override string Scheme {
-			get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
+			get { return Security.Mode == WebHttpSecurityMode.Transport ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
 		}
 
 		public WebHttpSecurity Security {

+ 10 - 0
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel/WebHttpBindingTest.cs

@@ -32,5 +32,15 @@ namespace MonoTests.System.ServiceModel
 			Assert.AreEqual (typeof (WebMessageEncodingBindingElement), bc [0].GetType (), "#2");
 			Assert.AreEqual (typeof (HttpTransportBindingElement), bc [1].GetType (), "#3");
 		}
+        
+        [Test]
+        public void DefaultSchemeBasedOnSecurityMode ()
+        {
+            WebHttpBinding b = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
+            Assert.AreEqual("http", b.Scheme, "#1");
+
+            b = new WebHttpBinding(WebHttpSecurityMode.Transport);
+            Assert.AreEqual("https", b.Scheme, "#2");
+        }
 	}
 }