* docs.make, Makefile.am: Build mono-file-formats{.tree,.zip},
[mono.git] / mcs / class / System / System.Net / HttpListenerRequest.cs
index 59e783ebe87148abc269d967b1ddca2f0cac6f29..4df1e4623992531959c4c6bfa25e910b7e84f0da 100644 (file)
@@ -38,7 +38,8 @@ namespace System.Net {
        public sealed class HttpListenerRequest
        {
                string [] accept_types;
-               int client_cert_error;
+//             int client_cert_error;
+//             bool no_get_certificate;
                Encoding content_encoding;
                long content_length;
                bool cl_set;
@@ -46,7 +47,6 @@ namespace System.Net {
                WebHeaderCollection headers;
                string method;
                Stream input_stream;
-               bool is_authenticated;
                Version version;
                NameValueCollection query_string; // check if null is ok, check if read-only, check case-sensitiveness
                string raw_url;
@@ -54,10 +54,11 @@ namespace System.Net {
                Uri url;
                Uri referrer;
                string [] user_languages;
-               bool no_get_certificate;
                HttpListenerContext context;
                bool is_chunked;
                static byte [] _100continue = Encoding.ASCII.GetBytes ("HTTP/1.1 100 Continue\r\n\r\n");
+               static readonly string [] no_body_methods = new string [] {
+                       "GET", "HEAD", "DELETE" };
 
                internal HttpListenerRequest (HttpListenerContext context)
                {
@@ -68,10 +69,6 @@ namespace System.Net {
 
                static char [] separators = new char [] { ' ' };
 
-#if false
-               static readonly string [] methods = new string [] { "GET", "POST", "HEAD",
-                                                               "PUT", "CONNECT", "MKCOL" };
-#endif
                internal void SetRequestLine (string req)
                {
                        string [] parts = req.Split (separators, 3);
@@ -85,7 +82,6 @@ namespace System.Net {
                                int ic = (int) c;
 
                                if ((ic >= 'A' && ic <= 'Z') ||
-                                   (ic >= 'a' && ic <= 'z') ||
                                    (ic > 32 && c < 127 && c != '(' && c != ')' && c != '<' &&
                                     c != '<' && c != '>' && c != '@' && c != ',' && c != ';' &&
                                     c != ':' && c != '\\' && c != '"' && c != '/' && c != '[' &&
@@ -95,17 +91,6 @@ namespace System.Net {
                                context.ErrorMessage = "(Invalid verb)";
                                return;
                        }
-                       
-#if false
-                       //
-                       // According to bug #80504 we should allow any verbs to go
-                       // through.
-                       //
-                       if (Array.IndexOf (methods, method) == -1) {
-                               context.ErrorMessage = "Invalid request line (verb).";
-                               return;
-                       }
-#endif
 
                        raw_url = parts [1];
                        if (parts [2].Length != 8 || !parts [2].StartsWith ("HTTP/")) {
@@ -148,14 +133,24 @@ namespace System.Net {
                internal void FinishInitialization ()
                {
                        string host = UserHostName;
-                       if (version > HttpVersion.Version10 && (host == null || host == "")) {
+                       if (version > HttpVersion.Version10 && (host == null || host.Length == 0)) {
                                context.ErrorMessage = "Invalid host name";
                                return;
                        }
 
-                       if (host == null || host == "")
+                       string path;
+                       Uri raw_uri;
+                       if (Uri.MaybeUri (raw_url) && Uri.TryCreate (raw_url, UriKind.Absolute, out raw_uri))
+                               path = raw_uri.PathAndQuery;
+                       else
+                               path = raw_url;
+
+                       if ((host == null || host.Length == 0))
                                host = UserHostAddress;
 
+                       if (raw_uri != null)
+                               host = raw_uri.Host;
+       
                        int colon = host.IndexOf (':');
                        if (colon >= 0)
                                host = host.Substring (0, colon);
@@ -164,18 +159,14 @@ namespace System.Net {
                                                                (IsSecureConnection) ? "https" : "http",
                                                                host,
                                                                LocalEndPoint.Port);
-                       try {
-                               url = new Uri (base_uri + raw_url);
-                       } catch {
-                               context.ErrorMessage = "Invalid url";
+
+                       if (!Uri.TryCreate (base_uri + path, UriKind.Absolute, out url)){
+                               context.ErrorMessage = "Invalid url: " + base_uri + path;
                                return;
                        }
 
                        CreateQueryString (url.Query);
 
-                       if (method == "GET" || method == "HEAD")
-                               return;
-
                        string t_encoding = null;
                        if (version >= HttpVersion.Version11) {
                                t_encoding = Headers ["Transfer-Encoding"];
@@ -186,7 +177,12 @@ namespace System.Net {
                                }
                        }
 
-                       bool is_chunked = (t_encoding == "chunked");
+                       is_chunked = (t_encoding == "chunked");
+
+                       foreach (string m in no_body_methods)
+                               if (string.Compare (method, m, StringComparison.InvariantCultureIgnoreCase) == 0)
+                                       return;
+
                        if (!is_chunked && !cl_set) {
                                context.Connection.SendError (null, 411);
                                return;
@@ -297,12 +293,16 @@ namespace System.Net {
                        get { return accept_types; }
                }
 
+               [MonoTODO ("Always returns 0")]
                public int ClientCertificateError {
                        get {
+/*                             
                                if (no_get_certificate)
                                        throw new InvalidOperationException (
                                                "Call GetClientCertificate() before calling this method.");
                                return client_cert_error;
+*/
+                               return 0;
                        }
                }
 
@@ -332,7 +332,7 @@ namespace System.Net {
                }
 
                public bool HasEntityBody {
-                       get { return (method == "GET" || method == "HEAD" || content_length <= 0 || is_chunked); }
+                       get { return (content_length > 0 || is_chunked); }
                }
 
                public NameValueCollection Headers {
@@ -347,8 +347,9 @@ namespace System.Net {
                        get { return input_stream; }
                }
 
+               [MonoTODO ("Always returns false")]
                public bool IsAuthenticated {
-                       get { return is_authenticated; }
+                       get { return false; }
                }
 
                public bool IsLocal {