From 861ab4c98d5fef7fc2333931e811bde31a6f6487 Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Thu, 28 Jan 2016 17:17:27 +0000 Subject: [System.Web] Test HttpRequest.Headers Add/Set/Remove In .NET while calling Add, Set or Remove of a HttpRequest read only collection a PlatformNotSupportedException is thrown. Covers #33809 --- .../System.Web/Test/System.Web/HttpRequestTest.cs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mcs/class/System.Web/Test/System.Web/HttpRequestTest.cs b/mcs/class/System.Web/Test/System.Web/HttpRequestTest.cs index 9ee9ebe1a1e..15d1f137a0a 100644 --- a/mcs/class/System.Web/Test/System.Web/HttpRequestTest.cs +++ b/mcs/class/System.Web/Test/System.Web/HttpRequestTest.cs @@ -254,6 +254,30 @@ namespace MonoTests.System.Web { { HttpContext.Current.Request.MapPath ("Web.config", "something", false); } + + [Test] + [ExpectedException (typeof (PlatformNotSupportedException))] + public void ReadOnlyHeadersAdd () + { + var r = new HttpRequest ("file", "http://www.gnome.org", "key=value&key2=value%32second"); + r.Headers.Add ("a","a"); + } + + [Test] + [ExpectedException (typeof (PlatformNotSupportedException))] + public void ReadOnlyHeadersSet () + { + var r = new HttpRequest ("file", "http://www.gnome.org", "key=value&key2=value%32second"); + r.Headers.Set ("a","a"); + } + + [Test] + [ExpectedException (typeof (PlatformNotSupportedException))] + public void ReadOnlyHeadersRemove () + { + var r = new HttpRequest ("file", "http://www.gnome.org", "key=value&key2=value%32second"); + r.Headers.Remove ("a"); + } } [TestFixture] -- cgit v1.2.3 From 1180f64665e4aa14994126abacc610ee032dadd2 Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Thu, 28 Jan 2016 17:21:37 +0000 Subject: [System.Web] HeadersCollection read only exception In reference source HttpHeaderCollection [1] when Add, Set or Remove is called and the collection is readonly a PlatformNotSupportedException is thrown. Mono HeadersCollection was throwing NotSupportedException and Microsoft.Owin.Host.SystemWeb.OwinCallContext.RemoveAcceptEncoding was not catching the exception because it was expecting PlatformNotSupportedException. Fixes #33809 [1] http://referencesource.microsoft.com/#System.Web/HttpHeaderCollection.cs,73 --- .../System.Web/System.Web/HeadersCollection.cs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mcs/class/System.Web/System.Web/HeadersCollection.cs b/mcs/class/System.Web/System.Web/HeadersCollection.cs index b2a1c73b7fc..fe2cf558afa 100644 --- a/mcs/class/System.Web/System.Web/HeadersCollection.cs +++ b/mcs/class/System.Web/System.Web/HeadersCollection.cs @@ -39,6 +39,30 @@ namespace System.Web { } + public override void Add (string name, string value) + { + if (IsReadOnly) + throw new PlatformNotSupportedException (); + + base.Set (name, value); + } + + public override void Set (string name, string value) + { + if (IsReadOnly) + throw new PlatformNotSupportedException (); + + base.Set (name, value); + } + + public override void Remove (string name) + { + if (IsReadOnly) + throw new PlatformNotSupportedException (); + + base.Remove (name); + } + protected override void InsertInfo() { HttpWorkerRequest worker_request = _request.WorkerRequest; -- cgit v1.2.3