9eb9fee8c191849981bfc80c8ed3eb4b98866cd2
[mono.git] / mcs / class / System.Web / System.Web / HttpResponseHeader.cs
1 //
2 // System.Web.HttpResponseHeader.cs 
3 //
4 // Author:
5 //      Chris Toshok (toshok@novell.com)
6 //
7
8 //
9 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Collections;
32 using System.Text;
33 using System.Web.Configuration;
34 using System.Web.Util;
35
36 namespace System.Web
37 {
38         abstract class BaseResponseHeader
39         {
40                 string headerValue;
41                 
42                 public string Value {
43                         get { return headerValue; }
44                         set {
45                                 string hname, hvalue;
46 #if NET_4_0
47                                 HttpEncoder.Current.HeaderNameValueEncode (null, value, out hname, out hvalue);
48 #else
49                                 HttpEncoder.HeaderNameValueEncode (null, value, out hname, out hvalue);
50 #endif
51                                 headerValue = hvalue;
52                         }
53                 }
54 /*        
55                 static bool headerCheckingEnabled;
56                 
57                 static BaseResponseHeader ()
58                 {
59                         HttpRuntimeSection section = HttpRuntime.Section;
60                         headerCheckingEnabled = section == null || section.EnableHeaderChecking;
61                 }
62 */
63
64                 internal BaseResponseHeader (string val)
65                 {
66                         Value = val;
67                 }
68                 
69                 internal abstract void SendContent (HttpWorkerRequest wr);
70         }
71
72         internal sealed class KnownResponseHeader : BaseResponseHeader
73         {
74                 public int ID;
75
76                 internal KnownResponseHeader (int ID, string val) : base (val)
77                 {
78                         this.ID = ID;
79                 }
80
81                 internal override void SendContent (HttpWorkerRequest wr)
82                 {
83                         wr.SendKnownResponseHeader (ID, Value);
84                 }
85         }
86
87         internal sealed class UnknownResponseHeader : BaseResponseHeader
88         {
89                 string headerName;
90                 
91                 public string Name {
92                         get { return headerName; }
93                         set {
94                                 string hname, hvalue;
95 #if NET_4_0
96                                 HttpEncoder.Current.HeaderNameValueEncode (value, null, out hname, out hvalue);
97 #else
98                                 HttpEncoder.HeaderNameValueEncode (value, null, out hname, out hvalue);
99 #endif
100                                 headerName = hname;
101                         }
102                 }
103                 
104
105                 public UnknownResponseHeader (string name, string val) : base (val)
106                 {
107                         Name = name;
108                 }
109         
110                 internal override void SendContent (HttpWorkerRequest wr)
111                 {
112                         wr.SendUnknownResponseHeader (Name, Value);
113                 }
114                 
115         }
116 }
117