summaryrefslogtreecommitdiff
path: root/lang/mono/patches/patch-cl
blob: 9add244aa5c80bfdc8909a7cf91c05574a0a6cd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$NetBSD: patch-cl,v 1.1 2008/09/01 09:28:54 kefren Exp $
--- mcs/class/System.Web/System.Web/HttpResponseHeader.cs	2008/08/21 16:19:17	111275
+++ mcs/class/System.Web/System.Web/HttpResponseHeader.cs	2008/08/21 16:51:54	111276
@@ -30,17 +30,65 @@
 
 using System.Collections;
 using System.Text;
+using System.Web.Configuration;
 
 namespace System.Web {
 
 	internal abstract class BaseResponseHeader {
-		public string Value;
+		string headerValue;
+		
+		public string Value {
+			get { return headerValue; }
+			set { headerValue = EncodeHeader (value); }
+		}
 	  
+		static bool headerCheckingEnabled;
+		
+		static BaseResponseHeader () {
+#if NET_2_0
+			HttpRuntimeSection section = WebConfigurationManager.GetSection ("system.web/httpRuntime") as HttpRuntimeSection;
+#else
+			HttpRuntimeConfig section = HttpContext.GetAppConfig ("system.web/httpRuntime") as HttpRuntimeConfig;
+#endif
+			headerCheckingEnabled = section == null || section.EnableHeaderChecking;
+		}
+
+
 		internal BaseResponseHeader (string val)
 		{
 			Value = val;
 		}
 
+		string EncodeHeader (string value)
+		{
+			if (value == null || value.Length == 0)
+				return value;
+			
+			if (headerCheckingEnabled) {
+				StringBuilder ret = new StringBuilder ();
+				int len = value.Length;
+
+				for (int i = 0; i < len; i++) {
+					switch (value [i]) {
+						case '\r':
+							ret.Append ("%0d");
+							break;
+
+						case '\n':
+							ret.Append ("%0a");
+							break;
+
+						default:
+							ret.Append (value [i]);
+							break;
+					}
+				}
+
+				return ret.ToString ();
+			} else
+				return value;
+		}
+		
 		internal abstract void SendContent (HttpWorkerRequest wr);
 	}