From: Mike Morano Date: Sun, 26 Oct 2014 15:14:08 +0000 (-0400) Subject: Add/update missing bits in order to support MVC5.2. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=d35449e99bc1315657ec41de2c90661bb82fc66a;p=mono.git Add/update missing bits in order to support MVC5.2. --- diff --git a/mcs/class/System.Web.Abstractions/System.Web/HttpContextWrapper.cs b/mcs/class/System.Web.Abstractions/System.Web/HttpContextWrapper.cs index 22feb8530d7..6581c0c1f77 100644 --- a/mcs/class/System.Web.Abstractions/System.Web/HttpContextWrapper.cs +++ b/mcs/class/System.Web.Abstractions/System.Web/HttpContextWrapper.cs @@ -183,10 +183,9 @@ namespace System.Web return w.GetSection (sectionName); } - [MonoTODO] public override object GetService (Type serviceType) { - throw new NotImplementedException (); + return ((IServiceProvider)w).GetService (serviceType); } #if NET_4_0 public override void RemapHandler (IHttpHandler handler) diff --git a/mcs/class/System.Web.Abstractions/System.Web/HttpRequestBase.cs b/mcs/class/System.Web.Abstractions/System.Web/HttpRequestBase.cs index 3a31754b949..bf1d6f576aa 100644 --- a/mcs/class/System.Web.Abstractions/System.Web/HttpRequestBase.cs +++ b/mcs/class/System.Web.Abstractions/System.Web/HttpRequestBase.cs @@ -138,7 +138,10 @@ namespace System.Web #if NET_4_5 public virtual ReadEntityBodyMode ReadEntityBodyMode { get { NotImplemented(); return ReadEntityBodyMode.Classic; } } + + public virtual UnvalidatedRequestValuesBase Unvalidated { get { NotImplemented (); return null; } } #endif + public virtual Uri Url { get { NotImplemented (); return null; } } public virtual Uri UrlReferrer { get { NotImplemented (); return null; } } diff --git a/mcs/class/System.Web.Abstractions/System.Web/HttpRequestWrapper.cs b/mcs/class/System.Web.Abstractions/System.Web/HttpRequestWrapper.cs index dc5098a3bec..35f631e37e7 100644 --- a/mcs/class/System.Web.Abstractions/System.Web/HttpRequestWrapper.cs +++ b/mcs/class/System.Web.Abstractions/System.Web/HttpRequestWrapper.cs @@ -208,6 +208,12 @@ namespace System.Web get { return w.TotalBytes; } } +#if NET_4_5 + public override UnvalidatedRequestValuesBase Unvalidated { + get { return new UnvalidatedRequestValuesWrapper (w.Unvalidated); } + } +#endif + public override Uri Url { get { return w.Url; } } diff --git a/mcs/class/System.Web/System.Web/HttpRequest.cs b/mcs/class/System.Web/System.Web/HttpRequest.cs index a2dd750eff4..6f845dbe108 100755 --- a/mcs/class/System.Web/System.Web/HttpRequest.cs +++ b/mcs/class/System.Web/System.Web/HttpRequest.cs @@ -80,13 +80,17 @@ namespace System.Web string unescaped_path; string original_path; string path_info; + string path_info_unvalidated; string raw_url; + string raw_url_unvalidated; WebROCollection all_params; - WebROCollection headers; + NameValueCollection headers; + WebROCollection headers_unvalidated; Stream input_stream; InputFilterStream input_filter; Stream filter; HttpCookieCollection cookies; + HttpCookieCollection cookies_unvalidated; string http_method; WebROCollection form; @@ -440,17 +444,27 @@ namespace System.Web } } - public HttpCookieCollection Cookies { + internal HttpCookieCollection CookiesNoValidation { get { - if (cookies == null) { + if (cookies_unvalidated == null) { if (worker_request == null) { - cookies = new HttpCookieCollection (); + cookies_unvalidated = new HttpCookieCollection (); } else { string cookie_hv = worker_request.GetKnownRequestHeader (HttpWorkerRequest.HeaderCookie); - cookies = new HttpCookieCollection (cookie_hv); + cookies_unvalidated = new HttpCookieCollection (cookie_hv); } } + return cookies_unvalidated; + } + } + + public HttpCookieCollection Cookies { + get { + if (cookies == null) { + cookies = CookiesNoValidation; + } + #if TARGET_J2EE // For J2EE portal support we emulate cookies using the session. GetSessionCookiesForPortal (cookies); @@ -737,10 +751,20 @@ namespace System.Web } } + internal NameValueCollection HeadersNoValidation { + get { + if (headers_unvalidated == null) { + headers_unvalidated = new HeadersCollection (this); + } + + return headers_unvalidated; + } + } + public NameValueCollection Headers { get { if (headers == null) { - headers = new HeadersCollection (this); + headers = HeadersNoValidation; #if NET_4_0 if (validateRequestNewMode) { RequestValidator validator = RequestValidator.Current; @@ -1226,12 +1250,23 @@ namespace System.Web } } + internal string PathInfoNoValidation { + get { + if (path_info_unvalidated == null) { + if (worker_request == null) + return String.Empty; + + path_info_unvalidated = worker_request.GetPathInfo () ?? String.Empty; + } + + return path_info_unvalidated; + } + } + public string PathInfo { get { if (path_info == null) { - if (worker_request == null) - return String.Empty; - path_info = worker_request.GetPathInfo () ?? String.Empty; + path_info = PathInfoNoValidation; #if NET_4_0 if (validateRequestNewMode) { RequestValidator validator = RequestValidator.Current; @@ -1335,16 +1370,26 @@ namespace System.Web } } - public string RawUrl { + internal string RawUrlUnvalidated { get { - if (raw_url == null) { + if (raw_url_unvalidated == null) { if (worker_request != null) - raw_url = worker_request.GetRawUrl (); + raw_url_unvalidated = worker_request.GetRawUrl (); else - raw_url = UrlComponents.Path + UrlComponents.Query; + raw_url_unvalidated = UrlComponents.Path + UrlComponents.Query; - if (raw_url == null) - raw_url = String.Empty; + if (raw_url_unvalidated == null) + raw_url_unvalidated = String.Empty; + } + + return raw_url_unvalidated; + } + } + + public string RawUrl { + get { + if (raw_url == null) { + raw_url = RawUrlUnvalidated; #if NET_4_0 if (validateRequestNewMode) { RequestValidator validator = RequestValidator.Current; @@ -1398,6 +1443,26 @@ namespace System.Web } } +#if NET_4_5 + public UnvalidatedRequestValues Unvalidated { + get { + var vals = new UnvalidatedRequestValues (); + + vals.Cookies = CookiesNoValidation; + vals.Files = Files; + vals.Form = FormUnvalidated; + vals.Headers = HeadersNoValidation; + vals.Path = PathNoValidation; + vals.PathInfo = PathInfoNoValidation; + vals.QueryString = QueryStringUnvalidated; + vals.RawUrl = RawUrlUnvalidated; + vals.Url = Url; + + return vals; + } + } +#endif + public Uri Url { get { if (cached_url == null) { diff --git a/mcs/class/System.Web/System.Web/UnvalidatedRequestValues.cs b/mcs/class/System.Web/System.Web/UnvalidatedRequestValues.cs new file mode 100644 index 00000000000..707b67e4139 --- /dev/null +++ b/mcs/class/System.Web/System.Web/UnvalidatedRequestValues.cs @@ -0,0 +1,66 @@ +// +// System.Web.UnvalidatedRequestValues.cs +// +// Author: +// Mike Morano +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Specialized; + + +namespace System.Web { + public sealed class UnvalidatedRequestValues { + public HttpCookieCollection Cookies { get; internal set; } + public HttpFileCollection Files { get; internal set; } + public NameValueCollection Form { get; internal set; } + public NameValueCollection Headers { get; internal set; } + public string Path { get; internal set; } + public string PathInfo { get; internal set; } + public NameValueCollection QueryString { get; internal set; } + public string RawUrl { get; internal set; } + public Uri Url { get; internal set; } + + public string this[string field] { + get { + if (Form != null && Form [field] != null) { + return Form [field]; + } + + if (Cookies != null && Cookies [field] != null) { + return Cookies [field].Value; + } + + if (QueryString != null && QueryString [field] != null) { + return QueryString [field]; + } + + // msdn docs also suggest the ServerVariables are inspected by this indexer, + // but that seems odd given what is available in this class + + return null; + } + } + } +} diff --git a/mcs/class/System.Web/System.Web/UnvalidatedRequestValuesBase.cs b/mcs/class/System.Web/System.Web/UnvalidatedRequestValuesBase.cs new file mode 100644 index 00000000000..9b54b072e28 --- /dev/null +++ b/mcs/class/System.Web/System.Web/UnvalidatedRequestValuesBase.cs @@ -0,0 +1,90 @@ +// +// System.Web.UnvalidatedRequestValuesBase.cs +// +// Author: +// Mike Morano +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Specialized; + + +namespace System.Web { + public abstract class UnvalidatedRequestValuesBase { + void NotImplemented () + { + throw new NotImplementedException (); + } + + public virtual HttpCookieCollection Cookies + { + get { NotImplemented (); return null; } + } + + public virtual HttpFileCollection Files + { + get { NotImplemented (); return null; } + } + + public virtual NameValueCollection Form + { + get { NotImplemented (); return null; } + } + + public virtual NameValueCollection Headers + { + get { NotImplemented (); return null; } + } + + public virtual string this[string field] + { + get { NotImplemented (); return null; } + } + + public virtual string Path + { + get { NotImplemented (); return null; } + } + + public virtual string PathInfo + { + get { NotImplemented (); return null; } + } + + public virtual NameValueCollection QueryString + { + get { NotImplemented (); return null; } + } + + public virtual string RawUrl + { + get { NotImplemented (); return null; } + } + + public virtual Uri Url + { + get { NotImplemented (); return null; } + } + } +} diff --git a/mcs/class/System.Web/System.Web/UnvalidatedRequestValuesWrapper.cs b/mcs/class/System.Web/System.Web/UnvalidatedRequestValuesWrapper.cs new file mode 100644 index 00000000000..e6b6084f2f2 --- /dev/null +++ b/mcs/class/System.Web/System.Web/UnvalidatedRequestValuesWrapper.cs @@ -0,0 +1,92 @@ +// +// System.Web.UnvalidatedRequestValuesWrapper.cs +// +// Author: +// Mike Morano +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections.Specialized; + + +namespace System.Web { + public class UnvalidatedRequestValuesWrapper : UnvalidatedRequestValuesBase { + UnvalidatedRequestValues rv; + + public UnvalidatedRequestValuesWrapper (UnvalidatedRequestValues requestValues) + { + rv = requestValues; + } + + public override HttpCookieCollection Cookies + { + get { return rv.Cookies; } + } + + public override HttpFileCollection Files + { + get { return rv.Files; } + } + + public override NameValueCollection Form + { + get { return rv.Form; } + } + + public override NameValueCollection Headers + { + get { return rv.Headers; } + } + + public override string this[string field] + { + get { return rv[field]; } + } + + public override string Path + { + get { return rv.Path; } + } + + public override string PathInfo + { + get { return rv.PathInfo; } + } + + public override NameValueCollection QueryString + { + get { return rv.QueryString; } + } + + public override string RawUrl + { + get { return rv.RawUrl; } + } + + public override Uri Url + { + get { return rv.Url; } + } + } +} diff --git a/mcs/class/System.Web/net_4_5_System.Web.dll.sources b/mcs/class/System.Web/net_4_5_System.Web.dll.sources index 04c7cacd659..f53e5bb9b76 100644 --- a/mcs/class/System.Web/net_4_5_System.Web.dll.sources +++ b/mcs/class/System.Web/net_4_5_System.Web.dll.sources @@ -2,4 +2,6 @@ System.Web/MimeMapping.cs System.Web/ReadEntityBodyMode.cs - +System.Web/UnvalidatedRequestValues.cs +System.Web/UnvalidatedRequestValuesBase.cs +System.Web/UnvalidatedRequestValuesWrapper.cs