Merge branch 'alexischr/nursery-canaries-managed-alloc'
[mono.git] / mcs / class / System.Web / System.Web / HttpResponseHeader.cs
index 3c6a97ba0c0079dc067c3d15a0f0affaaae913e4..574bbade505e556e0881c3c6f1ecea296e67f46f 100644 (file)
@@ -1,10 +1,12 @@
-// 
-// System.Web.HttpResponseHeader
+//
+// System.Web.HttpResponseHeader.cs 
 //
 // Author:
-//   Patrik Torstensson (Patrik.Torstensson@labs2.com)
+//     Chris Toshok (toshok@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
 // 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;
 
-namespace System.Web {
-       class HttpResponseHeader {
-               string header;
-               string val;
-               int header_id;
-               static char [] CRLF = { '\r', '\n' };
+using System.Collections;
+using System.Text;
+using System.Web.Configuration;
+using System.Web.Util;
 
-               internal HttpResponseHeader (int KnowHeaderId, string val)
+namespace System.Web
+{
+       abstract class BaseResponseHeader
+       {
+               string headerValue;
+               
+               public string Value {
+                       get { return headerValue; }
+                       set {
+                               string hname, hvalue;
+                               HttpEncoder.Current.HeaderNameValueEncode (null, value, out hname, out hvalue);
+                               headerValue = hvalue;
+                       }
+               }
+/*       
+               static bool headerCheckingEnabled;
+               
+               static BaseResponseHeader ()
                {
-                       header_id = KnowHeaderId;
-                       this.val = val;
+                       HttpRuntimeSection section = HttpRuntime.Section;
+                       headerCheckingEnabled = section == null || section.EnableHeaderChecking;
                }
+*/
 
-               internal HttpResponseHeader (string header, string val) {
-                       header = header;
-                       this.val = val;
+               internal BaseResponseHeader (string val)
+               {
+                       Value = val;
                }
+               
+               internal abstract void SendContent (HttpWorkerRequest wr);
+       }
 
-               internal string Name {
-                       get {
-                               if (null == header)
-                                       return HttpWorkerRequest.GetKnownResponseHeaderName (header_id);
+       internal sealed class KnownResponseHeader : BaseResponseHeader
+       {
+               public int ID;
 
-                               return header;
-                       }
+               internal KnownResponseHeader (int ID, string val) : base (val)
+               {
+                       this.ID = ID;
                }
 
-               internal string Value {
-                       get { return val; }
-                       set { val = value; }
+               internal override void SendContent (HttpWorkerRequest wr)
+               {
+                       wr.SendKnownResponseHeader (ID, Value);
                }
+       }
 
-               internal void SendContent (HttpWorkerRequest WorkerRequest)
-               {
-                       // use URL encoding on the value (see bug #75392)
-                       // but only for CR and LF. Other characters are left untouched.
-                       string actual_val = val;
-                       if (actual_val != null) {
-                               int crlf = actual_val.IndexOfAny (CRLF);
-                               if (crlf >= 0) {
-                                       actual_val = actual_val.Replace ("\r", "%0d");
-                                       actual_val = actual_val.Replace ("\n", "%0a");
-                               }
+       internal sealed class UnknownResponseHeader : BaseResponseHeader
+       {
+               string headerName;
+               
+               public string Name {
+                       get { return headerName; }
+                       set {
+                               string hname, hvalue;
+                               HttpEncoder.Current.HeaderNameValueEncode (value, null, out hname, out hvalue);
+                               headerName = hname;
                        }
+               }
+               
 
-                       if (null != header) {
-                               WorkerRequest.SendUnknownResponseHeader (header, actual_val);
-                       } else {
-                               WorkerRequest.SendKnownResponseHeader (header_id, actual_val);
-                       }
+               public UnknownResponseHeader (string name, string val) : base (val)
+               {
+                       Name = name;
+               }
+       
+               internal override void SendContent (HttpWorkerRequest wr)
+               {
+                       wr.SendUnknownResponseHeader (Name, Value);
                }
+               
        }
 }
+