Plug SplitOrderedList inside TemplateControl.
[mono.git] / mcs / class / System.Web / System.Web / ServerVariablesCollection.cs
index 50fc7efbe3820ae2d1e03ffa6199c5b276a0d79e..21677e8d0a4ae624b3ed846ffaac5e4cf96d90bd 100644 (file)
@@ -7,7 +7,7 @@
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
 //
 // (c) 2004 Mainsoft, Inc. (http://www.mainsoft.com)
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -35,18 +35,40 @@ using System.Collections.Specialized;
 using System.Runtime.Serialization;
 using System.Globalization;
 using System.Security.Permissions;
+using System.Security.Principal;
+using System.Web.Util;
 
 namespace System.Web
 {
-       class ServerVariablesCollection : BaseParamsCollection
+       sealed class ServerVariablesCollection : BaseParamsCollection
        {
-               HttpRequest request;
                bool loaded;
 
+               string QueryString {
+                       get {
+                               string qs = _request.QueryStringRaw;
+
+                               if (String.IsNullOrEmpty (qs))
+                                       return qs;
+
+                               if (qs [0] == '?')
+                                       return qs.Substring (1);
+
+                               return qs;
+                       }
+               }
+
+               IIdentity UserIdentity {
+                       get {
+                               HttpContext context = _request != null ? _request.Context : null;
+                               IPrincipal user = context != null ? context.User : null;
+                               return user != null ? user.Identity : null;
+                       }
+               }
+               
                public ServerVariablesCollection(HttpRequest request) : base(request)
                {
                        IsReadOnly = true;
-                       this.request = request;
                }
 
                void AppendKeyValue (StringBuilder sb, string key, string value, bool standard)
@@ -59,7 +81,7 @@ namespace System.Web
                        //
                        if (standard){
                                sb.Append ("HTTP_");
-                               sb.Append (key.ToUpper (CultureInfo.InvariantCulture).Replace ("-", "_"));
+                               sb.Append (key.ToUpper (Helpers.InvariantCulture).Replace ('-', '_'));
                                sb.Append (":");
                        } else {
                                sb.Append (key);
@@ -75,7 +97,7 @@ namespace System.Web
                        
                        for (int i = 0; i < HttpWorkerRequest.RequestHeaderMaximum; i++){
                                string val = wr.GetKnownRequestHeader (i);
-                               if (val == null || val == "")
+                               if (String.IsNullOrEmpty (val))
                                        continue;
                                string key = HttpWorkerRequest.GetKnownRequestHeaderName (i);
                                AppendKeyValue (sb, key, val, standard);
@@ -103,7 +125,7 @@ namespace System.Web
                                if (null != hvalue && hvalue.Length > 0) {
                                        hname = HttpWorkerRequest.GetKnownRequestHeaderName (i);
                                        if (null != hname && hname.Length > 0)
-                                               Add ("HTTP_" + hname.ToUpper (CultureInfo.InvariantCulture).Replace ('-', '_'), hvalue);
+                                               Add ("HTTP_" + hname.ToUpper (Helpers.InvariantCulture).Replace ('-', '_'), hvalue);
                                }
                        }
 
@@ -115,14 +137,14 @@ namespace System.Web
                                        if (hname == null)
                                                continue;
                                        hvalue = unknown [i][1];
-                                       Add ("HTTP_" + hname.ToUpper (CultureInfo.InvariantCulture).Replace ('-', '_'), hvalue);
+                                       Add ("HTTP_" + hname.ToUpper (Helpers.InvariantCulture).Replace ('-', '_'), hvalue);
                                }
                        }
                }
 
-               private void loadServerVariablesCollection()
+               void loadServerVariablesCollection()
                {
-                       HttpWorkerRequest wr = request.WorkerRequest;
+                       HttpWorkerRequest wr = _request.WorkerRequest;
                        if (loaded || (wr == null))
                                return;
 
@@ -134,12 +156,14 @@ namespace System.Web
                        Add("APPL_MD_PATH", wr.GetServerVariable("APPL_MD_PATH"));
                        Add("APPL_PHYSICAL_PATH", wr.GetServerVariable("APPL_PHYSICAL_PATH"));
 
-                       if (null != request.Context.User && request.Context.User.Identity.IsAuthenticated) {
-                               Add ("AUTH_TYPE", request.Context.User.Identity.AuthenticationType);
-                               Add ("AUTH_USER", request.Context.User.Identity.Name);
+                       IIdentity identity = UserIdentity;
+                       
+                       if (identity != null && identity.IsAuthenticated) {
+                               Add ("AUTH_TYPE", identity.AuthenticationType);
+                               Add ("AUTH_USER", identity.Name);
                        } else {
-                               Add ("AUTH_TYPE", "");
-                               Add ("AUTH_USER", "");
+                               Add ("AUTH_TYPE", String.Empty);
+                               Add ("AUTH_USER", String.Empty);
                        }
 
                        Add("AUTH_PASSWORD", wr.GetServerVariable("AUTH_PASSWORD"));
@@ -158,7 +182,7 @@ namespace System.Web
                        string sTmp = wr.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength);
                        if (null != sTmp)
                                Add ("CONTENT_LENGTH", sTmp);
-                       Add ("CONTENT_TYPE", request.ContentType);
+                       Add ("CONTENT_TYPE", _request.ContentType);
 
                        Add("GATEWAY_INTERFACE", wr.GetServerVariable("GATEWAY_INTERFACE"));
                        Add("HTTPS", wr.GetServerVariable("HTTPS"));
@@ -169,14 +193,14 @@ namespace System.Web
                        Add("INSTANCE_ID", wr.GetServerVariable("INSTANCE_ID"));
                        Add("INSTANCE_META_PATH", wr.GetServerVariable("INSTANCE_META_PATH"));
                        Add("LOCAL_ADDR", wr.GetLocalAddress());
-                       Add("PATH_INFO", request.PathInfo);
-                       Add("PATH_TRANSLATED", request.PhysicalPath);
-                       Add("QUERY_STRING", request.QueryStringRaw);
-                       Add("REMOTE_ADDR", request.UserHostAddress);
-                       Add("REMOTE_HOST", request.UserHostName);
+                       Add("PATH_INFO", _request.PathInfo);
+                       Add("PATH_TRANSLATED", _request.PhysicalPath);
+                       Add("QUERY_STRING", QueryString);
+                       Add("REMOTE_ADDR", _request.UserHostAddress);
+                       Add("REMOTE_HOST", _request.UserHostName);
                        Add("REMOTE_PORT", wr.GetRemotePort ().ToString ());
-                       Add("REQUEST_METHOD", request.HttpMethod);
-                       Add("SCRIPT_NAME", request.FilePath);
+                       Add("REQUEST_METHOD", _request.HttpMethod);
+                       Add("SCRIPT_NAME", _request.FilePath);
                        Add("SERVER_NAME", wr.GetServerName());
                        Add("SERVER_PORT", wr.GetLocalPort().ToString());
                        if (wr.IsSecure()) 
@@ -185,7 +209,7 @@ namespace System.Web
                                Add("SERVER_PORT_SECURE", "0");
                        Add("SERVER_PROTOCOL", wr.GetHttpVersion());
                        Add("SERVER_SOFTWARE", wr.GetServerVariable("SERVER_SOFTWARE"));
-                       Add ("URL", request.FilePath);
+                       Add ("URL", _request.FilePath);
 
                        AddHeaderVariables (wr);
 
@@ -202,21 +226,24 @@ namespace System.Web
                {
                        if ((name == null) || (this._request == null))
                                return null;
-                       name = name.ToUpper (CultureInfo.InvariantCulture);
-                       Console.WriteLine ("InternalGet {0}", name);
+                       name = name.ToUpper (Helpers.InvariantCulture);
+                       IIdentity identity;
+                       
                        switch (name) {
                                case "AUTH_TYPE":
-                                       if (null != _request.Context.User && _request.Context.User.Identity.IsAuthenticated)
-                                               return _request.Context.User.Identity.AuthenticationType;
+                                       identity = UserIdentity;
+                                       if (identity != null && identity.IsAuthenticated)
+                                               return identity.AuthenticationType;
                                        else
                                                return string.Empty;
                                case "AUTH_USER":
-                                       if (null != _request.Context.User && _request.Context.User.Identity.IsAuthenticated)
-                                               return _request.Context.User.Identity.Name;
+                                       identity = UserIdentity;
+                                       if (identity != null && identity.IsAuthenticated)
+                                               return identity.Name;
                                        else
                                                return string.Empty;
                                case "QUERY_STRING":
-                                       return this._request.QueryStringRaw;
+                                       return QueryString;
                                case "PATH_INFO":
                                        return this._request.PathInfo;
                                case "PATH_TRANSLATED":
@@ -245,10 +272,6 @@ namespace System.Web
                                        return _request.WorkerRequest.GetLocalPort ().ToString ();
                                case "APPL_PHYSICAL_PATH":
                                        return _request.WorkerRequest.GetAppPathTranslated ();
-                               case "REMOTE_USER":
-                                       return (_request.Context.User != null && _request.Context.User.Identity.IsAuthenticated) ?
-                                               _request.Context.User.Identity.Name :
-                                               String.Empty;
                                case "URL":
                                        return _request.FilePath;
                                case "SERVER_PORT_SECURE":
@@ -257,6 +280,7 @@ namespace System.Web
                                        return Fill (_request.WorkerRequest, true);
                                case "ALL_RAW":
                                        return Fill (_request.WorkerRequest, false);
+                               case "REMOTE_USER":
                                case "SERVER_SOFTWARE":
                                case "APPL_MD_PATH":
                                case "AUTH_PASSWORD":