Merge pull request #2530 from lambdageek/monoerror-mono_string_new
[mono.git] / mcs / class / System.Web / System.Web / HttpWorkerRequest.cs
old mode 100644 (file)
new mode 100755 (executable)
index a7a5e7a..0c91350
@@ -6,7 +6,7 @@
 //
 
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2009 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
 //
 
 using System.Collections;
+using System.Collections.Generic;
+using System.Collections.Specialized;
 using System.Runtime.InteropServices;
 using System.Security.Permissions;
 using System.Web.UI;
-using System.Collections.Specialized;
-
-namespace System.Web {
 
+namespace System.Web
+{
        // CAS
        [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        // attributes
        [ComVisible (false)]
-       public abstract class HttpWorkerRequest {
-
+       public abstract partial class HttpWorkerRequest
+       {
                public delegate void EndOfSendNotification (HttpWorkerRequest wr, object extraData);
 
                public const int HeaderCacheControl = 0;
@@ -105,18 +106,24 @@ namespace System.Web {
                public const int ReasonCacheSecurity = 3;
                public const int ReasonClientDisconnect = 4;
                public const int ReasonDefault = 0;
-
-               static readonly Hashtable RequestHeaderIndexer;
-               static readonly Hashtable ResponseHeaderIndexer;
-
-               static HttpWorkerRequest() {
-                       RequestHeaderIndexer = CollectionsUtil.CreateCaseInsensitiveHashtable(RequestHeaderMaximum);
+               static readonly Dictionary <string, int> RequestHeaderIndexer;
+               static readonly Dictionary <string, int> ResponseHeaderIndexer;
+               
+               static HttpWorkerRequest ()
+               {
+                       RequestHeaderIndexer = new Dictionary <string, int> (StringComparer.OrdinalIgnoreCase);                 
                        for (int i = 0; i < RequestHeaderMaximum; i++)
-                               RequestHeaderIndexer[GetKnownRequestHeaderName(i)] = i;
+                               RequestHeaderIndexer.Add (GetKnownRequestHeaderName(i), i);
 
-                       ResponseHeaderIndexer = CollectionsUtil.CreateCaseInsensitiveHashtable(ResponseHeaderMaximum);
+                       ResponseHeaderIndexer = new Dictionary <string, int> (StringComparer.OrdinalIgnoreCase);
                        for (int i = 0; i < ResponseHeaderMaximum; i++)
-                               ResponseHeaderIndexer[GetKnownResponseHeaderName(i)] = i;
+                               ResponseHeaderIndexer.Add (GetKnownResponseHeaderName(i), i);
+               }
+
+               bool started_internally;
+               internal bool StartedInternally {
+                       get { return started_internally; }
+                       set { started_internally = value; }
                }
 
                public virtual string MachineConfigPath {
@@ -131,7 +138,6 @@ namespace System.Web {
                        }
                }
 
-#if NET_2_0
                public virtual Guid RequestTraceIdentifier {
                        get { return Guid.Empty; }
                }
@@ -139,7 +145,6 @@ namespace System.Web {
                public virtual string RootWebConfigPath {
                        get { return null; }
                }
-#endif
 
                public virtual void CloseConnection ()
                {
@@ -189,7 +194,7 @@ namespace System.Web {
                {
                        return null;
                }
-#if NET_2_0
+
                public virtual int GetPreloadedEntityBody (byte[] buffer, int offset)
                {
                        return 0;
@@ -199,7 +204,7 @@ namespace System.Web {
                {
                        return 0;
                }
-#endif
+
                public virtual string GetProtocol ()
                {
                        if (IsSecure ())
@@ -232,12 +237,12 @@ namespace System.Web {
                {
                        return null;
                }
-#if NET_2_0
+
                public virtual int GetTotalEntityBodyLength ()
                {
                        return 0;
                }
-#endif
+
                public virtual string GetUnknownRequestHeader (string name)
                {
                        return null;
@@ -290,23 +295,28 @@ namespace System.Web {
                {
                        return 0;
                }
-#if NET_2_0
+
                public virtual int ReadEntityBody (byte [] buffer, int offset, int size)
                {
-                       return 0;
+                       byte[] temp = new byte [size];
+                       int n = ReadEntityBody (temp, size);
+
+                       if(n > 0)
+                               Array.Copy (temp, 0, buffer, offset, n);
+
+                       return n;
                }
-#endif
-               public virtual void SendCalculatedContentLength (int contentLength)
+
+               public virtual void SendCalculatedContentLength (long contentLength)
                {
-                       throw new NotImplementedException ();
+                       SendCalculatedContentLength ((int)contentLength);
                }
 
-#if TARGET_JVM
-               public virtual void SendResponseFromMemory (IntPtr data, int length)
+               public virtual void SendCalculatedContentLength (int contentLength)
                {
-                       throw new NotImplementedException("SendResponseFromMemory: unsafe buffers (IntPtr) are not supported");
+                       // apparently does nothing in MS.NET
                }
-#else
+
                public virtual void SendResponseFromMemory (IntPtr data, int length)
                {
                        if (data != IntPtr.Zero) {
@@ -315,7 +325,6 @@ namespace System.Web {
                                SendResponseFromMemory (copy, length);
                        }
                }
-#endif
 
                public virtual void SetEndOfSendNotification (HttpWorkerRequest.EndOfSendNotification callback, object extraData)
                {
@@ -345,52 +354,9 @@ namespace System.Web {
                
                public static int GetKnownRequestHeaderIndex (string header)
                {
-                       switch (header){
-                       case "Cache-Control": return HeaderCacheControl;
-                       case "Connection": return HeaderConnection;
-                       case "Date": return HeaderDate;
-                       case "Keep-Alive": return HeaderKeepAlive;
-                       case "Pragma": return HeaderPragma;
-                       case "Trailer": return HeaderTrailer;
-                       case "Transfer-Encoding": return HeaderTransferEncoding;
-                       case "Upgrade": return HeaderUpgrade;
-                       case "Via": return HeaderVia;
-                       case "Warning": return HeaderWarning;
-                       case "Allow": return HeaderAllow;
-                       case "Content-Length": return HeaderContentLength;
-                       case "Content-Type": return HeaderContentType;
-                       case "Content-Encoding": return HeaderContentEncoding;
-                       case "Content-Language": return HeaderContentLanguage;
-                       case "Content-Location": return HeaderContentLocation;
-                       case "Content-MD5": return HeaderContentMd5;
-                       case "Content-Range": return HeaderContentRange;
-                       case "Expires": return HeaderExpires;
-                       case "Last-Modified": return HeaderLastModified;
-                       case "Accept": return HeaderAccept;
-                       case "Accept-Charset": return HeaderAcceptCharset;
-                       case "Accept-Encoding": return HeaderAcceptEncoding;
-                       case "Accept-Language": return HeaderAcceptLanguage;
-                       case "Authorization": return HeaderAuthorization;
-                       case "Cookie": return HeaderCookie;
-                       case "Expect": return HeaderExpect;
-                       case "From": return HeaderFrom;
-                       case "Host": return HeaderHost;
-                       case "If-Match": return HeaderIfMatch;
-                       case "If-Modified-Since": return HeaderIfModifiedSince;
-                       case "If-None-Match": return HeaderIfNoneMatch;
-                       case "If-Range": return HeaderIfRange;
-                       case "If-Unmodified-Since": return HeaderIfUnmodifiedSince;
-                       case "Max-Forwards": return HeaderMaxForwards;
-                       case "Proxy-Authorization": return HeaderProxyAuthorization;
-                       case "Referer": return HeaderReferer;
-                       case "Range": return HeaderRange;
-                       case "TE": return HeaderTe;
-                       case "User-Agent": return HeaderUserAgent;
-                       }
-
-                       object index = RequestHeaderIndexer[header];
-                       if (index != null)
-                               return (int)index;
+                       int index;
+                       if (RequestHeaderIndexer.TryGetValue (header, out index))
+                               return index;
 
                        return -1;
                }
@@ -445,42 +411,9 @@ namespace System.Web {
 
                public static int GetKnownResponseHeaderIndex (string header)
                {
-                       switch (header){
-                       case "Cache-Control": return HeaderCacheControl;
-                       case "Connection": return HeaderConnection;
-                       case "Date": return HeaderDate;
-                       case "Keep-Alive": return HeaderKeepAlive;
-                       case "Pragma": return HeaderPragma;
-                       case "Trailer": return HeaderTrailer;
-                       case "Transfer-Encoding": return HeaderTransferEncoding;
-                       case "Upgrade": return HeaderUpgrade;
-                       case "Via": return HeaderVia;
-                       case "Warning": return HeaderWarning;
-                       case "Allow": return HeaderAllow;
-                       case "Content-Length": return HeaderContentLength;
-                       case "Content-Type": return HeaderContentType;
-                       case "Content-Encoding": return HeaderContentEncoding;
-                       case "Content-Language": return HeaderContentLanguage;
-                       case "Content-Location": return HeaderContentLocation;
-                       case "Content-MD5": return HeaderContentMd5;
-                       case "Content-Range": return HeaderContentRange;
-                       case "Expires": return HeaderExpires;
-                       case "Last-Modified": return HeaderLastModified;
-                       case "Accept-Ranges": return HeaderAcceptRanges;
-                       case "Age": return HeaderAge;
-                       case "ETag": return HeaderEtag;
-                       case "Location": return HeaderLocation;
-                       case "Proxy-Authenticate":return HeaderProxyAuthenticate;
-                       case "Retry-After": return HeaderRetryAfter;
-                       case "Server": return HeaderServer;
-                       case "Set-Cookie": return HeaderSetCookie;
-                       case "Vary": return HeaderVary;
-                       case "WWW-Authenticate": return HeaderWwwAuthenticate;
-                       }
-
-                       object index = ResponseHeaderIndexer[header];
-                       if (index != null)
-                               return (int)index;
+                       int index;
+                       if (ResponseHeaderIndexer.TryGetValue (header, out index))
+                               return index;
 
                        return -1;
                }