3c6a97ba0c0079dc067c3d15a0f0affaaae913e4
[mono.git] / mcs / class / System.Web / System.Web / HttpResponseHeader.cs
1 // 
2 // System.Web.HttpResponseHeader
3 //
4 // Author:
5 //   Patrik Torstensson (Patrik.Torstensson@labs2.com)
6 //
7
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 using System;
29
30 namespace System.Web {
31         class HttpResponseHeader {
32                 string header;
33                 string val;
34                 int header_id;
35                 static char [] CRLF = { '\r', '\n' };
36
37                 internal HttpResponseHeader (int KnowHeaderId, string val)
38                 {
39                         header_id = KnowHeaderId;
40                         this.val = val;
41                 }
42
43                 internal HttpResponseHeader (string header, string val) {
44                         header = header;
45                         this.val = val;
46                 }
47
48                 internal string Name {
49                         get {
50                                 if (null == header)
51                                         return HttpWorkerRequest.GetKnownResponseHeaderName (header_id);
52
53                                 return header;
54                         }
55                 }
56
57                 internal string Value {
58                         get { return val; }
59                         set { val = value; }
60                 }
61
62                 internal void SendContent (HttpWorkerRequest WorkerRequest)
63                 {
64                         // use URL encoding on the value (see bug #75392)
65                         // but only for CR and LF. Other characters are left untouched.
66                         string actual_val = val;
67                         if (actual_val != null) {
68                                 int crlf = actual_val.IndexOfAny (CRLF);
69                                 if (crlf >= 0) {
70                                         actual_val = actual_val.Replace ("\r", "%0d");
71                                         actual_val = actual_val.Replace ("\n", "%0a");
72                                 }
73                         }
74
75                         if (null != header) {
76                                 WorkerRequest.SendUnknownResponseHeader (header, actual_val);
77                         } else {
78                                 WorkerRequest.SendKnownResponseHeader (header_id, actual_val);
79                         }
80                 }
81         }
82 }