WebHeaderCollection fixes
[mono.git] / mcs / class / System / Test / System.Net / WebHeaderCollectionTest.cs
1 //
2 // WebHeaderCollectionTest.cs - NUnit Test Cases for System.Net.WebHeaderCollection
3 //
4 // Authors:
5 //   Lawrence Pit (loz@cable.a2000.nl)
6 //   Martin Willemoes Hansen (mwh@sysrq.dk)
7 //   Gert Driesen (drieseng@users.sourceforge.net)
8 //   Gonzalo Paniagua Javier (gonzalo@novell.com)
9 //   Marek Safar  <marek.safar@gmail.com>
10 //
11 // (C) 2003 Martin Willemoes Hansen
12 //
13
14 using System;
15 using System.Collections;
16 using System.Collections.Specialized;
17 using System.IO;
18 using System.Net;
19 using System.Runtime.Serialization;
20 using System.Runtime.Serialization.Formatters;
21 using System.Runtime.Serialization.Formatters.Binary;
22
23 using NUnit.Framework;
24
25 namespace MonoTests.System.Net
26 {
27         [TestFixture]
28         public class WebHeaderCollectionTest
29         {
30                 WebHeaderCollection col;
31
32                 [SetUp]
33                 public void GetReady ()
34                 {
35                         col = new WebHeaderCollection ();
36                         col.Add ("Name1: Value1");
37                         col.Add ("Name2: Value2");
38                 }
39
40                 [Test]
41                 public void Add ()
42                 {
43                         try {
44                                 col.Add (null);
45                                 Assert.Fail ("#1");
46                         } catch (ArgumentNullException) { }
47                         try {
48                                 col.Add ("");
49                                 Assert.Fail ("#2");
50                         } catch (ArgumentException) { }
51                         try {
52                                 col.Add ("  ");
53                                 Assert.Fail ("#3");
54                         } catch (ArgumentException) { }
55                         try {
56                                 col.Add (":");
57                                 Assert.Fail ("#4");
58                         } catch (ArgumentException) { }
59                         try {
60                                 col.Add (" : ");
61                                 Assert.Fail ("#5");
62                         } catch (ArgumentException) { }
63
64                         try {
65                                 col.Add ("XHost: foo");
66                         } catch (ArgumentException) {
67                                 Assert.Fail ("#7");
68                         }
69
70                         // invalid values
71                         try {
72                                 col.Add ("XHost" + ((char) 0xa9) + ": foo");
73                                 Assert.Fail ("#8");
74                         } catch (ArgumentException) { }
75                         try {
76                                 col.Add ("XHost: foo" + (char) 0xa9);
77                         } catch (ArgumentException) {
78                                 Assert.Fail ("#9");
79                         }
80                         try {
81                                 col.Add ("XHost: foo" + (char) 0x7f);
82                                 Assert.Fail ("#10");
83                         } catch (ArgumentException) {
84                         }
85                         try {
86                                 col.Add (":value");
87                                 Assert.Fail ("#100");
88                         } catch (ArgumentException) {
89                         }
90
91                         try {
92                                 col.Add ("XHost", null);
93                         } catch (ArgumentException) {
94                                 Assert.Fail ("#11");
95                         }
96                         try {
97                                 col.Add ("XHost:");
98                         } catch (ArgumentException) {
99                                 Assert.Fail ("#12");
100                         }
101                 }
102
103                 [Test]
104                 public void AddRequestHeader ()
105                 {
106                         col.Add (HttpRequestHeader.Host, "hh");
107
108                         try {
109                                 col.Add (HttpResponseHeader.Age, "aa");
110                                 Assert.Fail ("#1");
111                         } catch (InvalidOperationException) {
112                         }
113                 }
114
115                 [Test]
116                 public void AddRestrictedDisabled ()
117                 {
118                         col.Add ("Accept", "aa");
119                         col.Add ("Content-Length", "bb");
120                         col.Add ("Keep-Alive", "cc");
121                         col.Add ("If-Modified-Since", "dd");
122                         col.Add ("aaany", null);
123                 }
124
125                 [Test]
126                 public void AddRestricted ()
127                 {
128                         col = CreateRestrictedHeaders ();
129
130                         try {
131                                 col.Add ("Accept", "cc");
132                                 Assert.Fail ("#1");
133                         } catch (ArgumentException) {
134                         }
135
136                         try {
137                                 col.Add (HttpRequestHeader.Host, "dd");
138                                 Assert.Fail ("#2");
139                         } catch (ArgumentException) {
140                         }
141                 }
142
143                 [Test]
144                 public void GetValues ()
145                 {
146                         WebHeaderCollection w = new WebHeaderCollection ();
147                         w.Add ("Hello", "H1");
148                         w.Add ("Hello", "H2");
149                         w.Add ("Hello", "H3,H4");
150
151                         string [] sa = w.GetValues ("Hello");
152                         Assert.AreEqual (3, sa.Length, "#1");
153                         Assert.AreEqual ("H1,H2,H3,H4", w.Get ("Hello"), "#2");
154
155                         w = new WebHeaderCollection ();
156                         w.Add ("Accept", "H1");
157                         w.Add ("Accept", "H2");
158                         w.Add ("Accept", "H3,  H4  ");
159                         Assert.AreEqual (3, w.GetValues (0).Length, "#3a");
160                         Assert.AreEqual (4, w.GetValues ("Accept").Length, "#3b");
161                         Assert.AreEqual ("H4", w.GetValues ("Accept")[3], "#3c");
162                         Assert.AreEqual ("H1,H2,H3,  H4", w.Get ("Accept"), "#4");
163
164                         w = new WebHeaderCollection ();
165                         w.Add ("Allow", "H1");
166                         w.Add ("Allow", "H2");
167                         w.Add ("Allow", "H3,H4");
168                         sa = w.GetValues ("Allow");
169                         Assert.AreEqual (4, sa.Length, "#5");
170                         Assert.AreEqual ("H1,H2,H3,H4", w.Get ("Allow"), "#6");
171
172                         w = new WebHeaderCollection ();
173                         w.Add ("AUTHorization", "H1, H2, H3");
174                         sa = w.GetValues ("authorization");
175                         Assert.AreEqual (3, sa.Length, "#9");
176
177                         w = new WebHeaderCollection ();
178                         w.Add ("proxy-authenticate", "H1, H2, H3");
179                         sa = w.GetValues ("Proxy-Authenticate");
180                         Assert.AreEqual (3, sa.Length, "#9");
181
182                         w = new WebHeaderCollection ();
183                         w.Add ("expect", "H1,\tH2,   H3  ");
184                         sa = w.GetValues ("EXPECT");
185                         Assert.AreEqual (3, sa.Length, "#10");
186                         Assert.AreEqual ("H2", sa [1], "#11");
187                         Assert.AreEqual ("H3", sa [2], "#12");
188
189                         try {
190                                 w.GetValues (null);
191                                 Assert.Fail ("#13");
192                         } catch (ArgumentNullException) { }
193                         Assert.AreEqual (null, w.GetValues (""), "#14");
194                         Assert.AreEqual (null, w.GetValues ("NotExistent"), "#15");
195
196                         w = new WebHeaderCollection ();
197                         w.Add ("Accept", null);
198                         Assert.AreEqual (1, w.GetValues ("Accept").Length, "#16");
199
200                         w = new WebHeaderCollection ();
201                         w.Add ("Accept", ",,,");
202                         Assert.AreEqual (3, w.GetValues ("Accept").Length, "#17");
203                 }
204
205                 [Test]
206                 public void Indexers ()
207                 {
208                         Assert.AreEqual ("Value1", ((NameValueCollection)col)[0], "#1.1");
209                         WebHeaderCollection w = new WebHeaderCollection ();
210                         w [HttpRequestHeader.CacheControl] = "Value2";
211                         Assert.AreEqual ("Value2", w[HttpRequestHeader.CacheControl], "#1.2");
212
213                         try {
214                                 w[HttpResponseHeader.Pragma] = "Value3";
215                                 Assert.Fail ("#1.3");
216                         } catch (InvalidOperationException) {
217                         }
218                 }
219
220                 [Test]
221                 public void Remove ()
222                 {
223                         col.Remove ("Name1");
224                         col.Remove ("NameNotExist");
225                         Assert.AreEqual (1, col.Count, "#1");
226                 }
227
228                 [Test]
229                 public void RemoveRestricted ()
230                 {
231                         col = CreateRestrictedHeaders ();
232
233                         try {
234                                 col.Add ("Host", "foo");
235                                 col.Remove ("Host");
236                                 Assert.Fail ("#2: should fail according to spec");
237                         } catch (ArgumentException) {}
238                 }
239
240                 [Test]
241                 public void Set ()
242                 {
243                         col.Add ("Name1", "Value1b");
244                         col.Set ("Name1", "\t  X  \t");
245                         Assert.AreEqual ("X", col.Get ("Name1"), "#1");
246                 }
247
248                 [Test]
249                 public void IsRestricted ()
250                 {
251                         Assert.IsTrue (!WebHeaderCollection.IsRestricted ("Xhost"), "#1");
252                         Assert.IsTrue (WebHeaderCollection.IsRestricted ("Host"), "#2");
253                         Assert.IsTrue (WebHeaderCollection.IsRestricted ("HOST"), "#3");
254                         Assert.IsTrue (WebHeaderCollection.IsRestricted ("Transfer-Encoding"), "#4");
255                         Assert.IsTrue (WebHeaderCollection.IsRestricted ("user-agent"), "#5");
256                         Assert.IsTrue (WebHeaderCollection.IsRestricted ("accept"), "#6");
257                         Assert.IsTrue (!WebHeaderCollection.IsRestricted ("accept-charset"), "#7");
258                 }
259
260                 [Test]
261                 public void ToStringTest ()
262                 {
263                         col.Add ("Name1", "Value1b");
264                         col.Add ("Name3", "Value3a\r\n Value3b");
265                         col.Add ("Name4", "   Value4   ");
266                         Assert.AreEqual ("Name1: Value1,Value1b\r\nName2: Value2\r\nName3: Value3a\r\n Value3b\r\nName4: Value4\r\n\r\n", col.ToString (), "#1");
267                         WebHeaderCollection w;
268                         w = new WebHeaderCollection ();
269                         w.Add (HttpResponseHeader.KeepAlive, "Value1");
270                         w.Add (HttpResponseHeader.WwwAuthenticate, "Value2");
271                         Assert.AreEqual ("Keep-Alive: Value1\r\nWWW-Authenticate: Value2\r\n\r\n", w.ToString (), "#2");
272                         w = new WebHeaderCollection ();
273                         w.Add (HttpRequestHeader.UserAgent, "Value1");
274                         w.Add (HttpRequestHeader.ContentMd5, "Value2");
275                         Assert.AreEqual ("User-Agent: Value1\r\nContent-MD5: Value2\r\n\r\n", w.ToString (), "#3");
276                 }
277
278                 [Test]
279 #if TARGET_JVM
280                 //FIXME: include Java serialization compliant tests - the order of object
281                 // in SerializationInfo should stay same to MS format...
282                 [Ignore ("The MS compliant binary serialization is not supported")]
283 #endif                  
284                 public void GetObjectData ()
285                 {
286                         SerializationInfo si = new SerializationInfo (typeof (WebHeaderCollection),
287                                 new FormatterConverter ());
288
289                         WebHeaderCollection headers = new WebHeaderCollection ();
290                         headers.Add ("Content-Type", "image/png");
291                         headers.Add ("No-Cache:off");
292                         headers.Add ("Disposition", "attach");
293
294                         ((ISerializable) headers).GetObjectData (si, new StreamingContext ());
295                         Assert.AreEqual (7, si.MemberCount, "#A");
296                         int i = 0;
297                         foreach (SerializationEntry entry in si) {
298                                 Assert.IsNotNull (entry.Name, "#B1:" + i);
299                                 Assert.IsNotNull (entry.ObjectType, "#B2:" + i);
300                                 Assert.IsNotNull (entry.Value, "#B3:" + i);
301
302                                 switch (i) {
303                                 case 0:
304                                         Assert.AreEqual ("Count", entry.Name, "#B4:" + i);
305                                         Assert.AreEqual (typeof (int), entry.ObjectType, "#B5:" + i);
306                                         Assert.AreEqual (3, entry.Value, "#B6:" + i);
307                                         break;
308                                 case 1:
309                                         Assert.AreEqual ("0", entry.Name, "#B4:" + i);
310                                         Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
311                                         Assert.AreEqual ("Content-Type", entry.Value, "#B6:" + i);
312                                         break;
313                                 case 2:
314                                         Assert.AreEqual ("3", entry.Name, "#B4:" + i);
315                                         Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
316                                         Assert.AreEqual ("image/png", entry.Value, "#B6:" + i);
317                                         break;
318                                 case 3:
319                                         Assert.AreEqual ("1", entry.Name, "#B4:" + i);
320                                         Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
321                                         Assert.AreEqual ("No-Cache", entry.Value, "#B6:" + i);
322                                         break;
323                                 case 4:
324                                         Assert.AreEqual ("4", entry.Name, "#B4:" + i);
325                                         Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
326                                         Assert.AreEqual ("off", entry.Value, "#B6:" + i);
327                                         break;
328                                 case 5:
329                                         Assert.AreEqual ("2", entry.Name, "#B4:" + i);
330                                         Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
331                                         Assert.AreEqual ("Disposition", entry.Value, "#B6:" + i);
332                                         break;
333                                 case 6:
334                                         Assert.AreEqual ("5", entry.Name, "#B4:" + i);
335                                         Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
336                                         Assert.AreEqual ("attach", entry.Value, "#B6:" + i);
337                                         break;
338                                 }
339                                 i++;
340                         }
341                 }
342
343                 [Test]
344 #if TARGET_JVM
345                 //FIXME: include Java serialization compliant tests
346                 [Ignore ("The MS compliant binary serialization is not supported")]
347 #endif          
348                 public void Serialize ()
349                 {
350                         WebHeaderCollection headers = new WebHeaderCollection ();
351                         headers.Add ("Content-Type", "image/png");
352                         headers.Add ("No-Cache:off");
353                         headers.Add ("Disposition", "attach");
354
355                         BinaryFormatter bf = new BinaryFormatter ();
356                         bf.AssemblyFormat = FormatterAssemblyStyle.Full;
357
358                         MemoryStream ms = new MemoryStream ();
359                         bf.Serialize (ms, headers);
360                         ms.Position = 0;
361
362                         byte [] buffer = new byte [ms.Length];
363                         ms.Read (buffer, 0, buffer.Length);
364                         Assert.AreEqual (_serialized, buffer);
365                 }
366
367                 [Test]
368 #if TARGET_JVM
369                 //FIXME: include Java serialization compliant tests
370                 [Ignore ("The MS compliant binary serialization format is not supported")]
371 #endif                          
372                 public void Deserialize ()
373                 {
374                         MemoryStream ms = new MemoryStream ();
375                         ms.Write (_serialized, 0, _serialized.Length);
376                         ms.Position = 0;
377
378                         BinaryFormatter bf = new BinaryFormatter ();
379                         WebHeaderCollection headers = (WebHeaderCollection) bf.Deserialize (ms);
380                 }
381
382                 private static readonly byte [] _serialized = new byte [] {
383                         0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
384                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x00, 0x00, 0x00,
385                         0x49, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x20, 0x56, 0x65,
386 #if NET_4_0
387                         0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x34, 0x2e, 0x30, 0x2e, 0x30,
388 #else
389                         0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x32, 0x2e, 0x30, 0x2e, 0x30,
390 #endif
391                         0x2e, 0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74, 0x75, 0x72, 0x65,
392                         0x3d, 0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c, 0x2c, 0x20, 0x50,
393                         0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x54, 0x6f, 0x6b,
394                         0x65, 0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35, 0x63, 0x35, 0x36,
395                         0x31, 0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39, 0x05, 0x01, 0x00,
396                         0x00, 0x00, 0x1e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4e,
397                         0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x48, 0x65, 0x61, 0x64, 0x65,
398                         0x72, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
399                         0x07, 0x00, 0x00, 0x00, 0x05, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x01,
400                         0x30, 0x01, 0x33, 0x01, 0x31, 0x01, 0x34, 0x01, 0x32, 0x01, 0x35,
401                         0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0x02, 0x00, 0x00,
402                         0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x0c,
403                         0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70,
404                         0x65, 0x06, 0x04, 0x00, 0x00, 0x00, 0x09, 0x69, 0x6d, 0x61, 0x67,
405                         0x65, 0x2f, 0x70, 0x6e, 0x67, 0x06, 0x05, 0x00, 0x00, 0x00, 0x08,
406                         0x4e, 0x6f, 0x2d, 0x43, 0x61, 0x63, 0x68, 0x65, 0x06, 0x06, 0x00,
407                         0x00, 0x00, 0x03, 0x6f, 0x66, 0x66, 0x06, 0x07, 0x00, 0x00, 0x00,
408                         0x0b, 0x44, 0x69, 0x73, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
409                         0x6e, 0x06, 0x08, 0x00, 0x00, 0x00, 0x06, 0x61, 0x74, 0x74, 0x61,
410                         0x63, 0x68, 0x0b
411                 };
412
413                 [Test]
414                 public void IsRestricted_InvalidChars_1 ()
415                 {
416                         // Not allowed:
417                         //      0-32
418                         //      34
419                         //      39-41
420                         //      44
421                         //      47
422                         //      91-93
423                         //      123
424                         //      125
425                         //      >= 127
426                         int [] singles = new int [] { 34, 44, 47, 123, 125 };
427                         foreach (int single in singles) {
428                                 try {
429                                         WebHeaderCollection.IsRestricted (new string ((char) single, 1));
430                                         Assert.Fail (String.Format ("{0}: {1}", single, (char) single));
431                                 } catch (ArgumentException) {
432                                 }
433                         }
434                         for (int i = 0; i <= 32; i++) {
435                                 try {
436                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1));
437                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
438                                 } catch (ArgumentException) {
439                                 }
440                         }
441                         for (int i = 39; i <= 41; i++) {
442                                 try {
443                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1));
444                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
445                                 } catch (ArgumentException) {
446                                 }
447                         }
448                         for (int i = 91; i <= 93; i++) {
449                                 try {
450                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1));
451                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
452                                 } catch (ArgumentException) {
453                                 }
454                         }
455                         for (int i = 127; i <= 255; i++) {
456                                 try {
457                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1));
458                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
459                                 } catch (ArgumentException) {
460                                 }
461                         }
462                 }
463
464                 [Test]
465                 public void IsRestricted_InvalidChars_Request_2 ()
466                 {
467                         // Not allowed:
468                         //      0-32
469                         //      34
470                         //      39-41
471                         //      44
472                         //      47
473                         //      91-93
474                         //      123
475                         //      125
476                         //      >= 127
477                         int [] singles = new int [] { 34, 44, 47, 123, 125 };
478                         foreach (int single in singles) {
479                                 try {
480                                         WebHeaderCollection.IsRestricted (new string ((char) single, 1), false);
481                                         Assert.Fail (String.Format ("{0}: {1}", single, (char) single));
482                                 } catch (ArgumentException) {
483                                 }
484                         }
485                         for (int i = 0; i <= 32; i++) {
486                                 try {
487                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1), false);
488                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
489                                 } catch (ArgumentException) {
490                                 }
491                         }
492                         for (int i = 39; i <= 41; i++) {
493                                 try {
494                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1), false);
495                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
496                                 } catch (ArgumentException) {
497                                 }
498                         }
499                         for (int i = 91; i <= 93; i++) {
500                                 try {
501                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1), false);
502                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
503                                 } catch (ArgumentException) {
504                                 }
505                         }
506                         for (int i = 127; i <= 255; i++) {
507                                 try {
508                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1), false);
509                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
510                                 } catch (ArgumentException) {
511                                 }
512                         }
513                 }
514
515                 [Test]
516                 public void IsRestricted_InvalidChars_Response_2 ()
517                 {
518                         // Not allowed:
519                         //      0-32
520                         //      34
521                         //      39-41
522                         //      44
523                         //      47
524                         //      91-93
525                         //      123
526                         //      125
527                         //      >= 127
528                         int [] singles = new int [] { 34, 44, 47, 123, 125 };
529                         foreach (int single in singles) {
530                                 try {
531                                         WebHeaderCollection.IsRestricted (new string ((char) single, 1), true);
532                                         Assert.Fail (String.Format ("{0}: {1}", single, (char) single));
533                                 } catch (ArgumentException) {
534                                 }
535                         }
536                         for (int i = 0; i <= 32; i++) {
537                                 try {
538                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1), true);
539                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
540                                 } catch (ArgumentException) {
541                                 }
542                         }
543                         for (int i = 39; i <= 41; i++) {
544                                 try {
545                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1), true);
546                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
547                                 } catch (ArgumentException) {
548                                 }
549                         }
550                         for (int i = 91; i <= 93; i++) {
551                                 try {
552                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1), true);
553                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
554                                 } catch (ArgumentException) {
555                                 }
556                         }
557                         for (int i = 127; i <= 255; i++) {
558                                 try {
559                                         WebHeaderCollection.IsRestricted (new string ((char) i, 1), true);
560                                         Assert.Fail (String.Format ("{0}: {1}", i, (char) i));
561                                 } catch (ArgumentException) {
562                                 }
563                         }
564                 }
565
566                 static string [] request_headers = new string [] {
567                         "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language", "Accept-Ranges", "Authorization", 
568                         "Cache-Control", "Connection", "Cookie", "Content-Length", "Content-Type", "Date", 
569                         "Expect", "From", "Host", "If-Match", "If-Modified-Since", "If-None-Match", 
570                         "If-Range", "If-Unmodified-Since", "Max-Forwards", "Pragma", "Proxy-Authorization", "Proxy-Connection",
571                         "Range", "Referer", "TE", "Transfer-Encoding", "Upgrade", "User-Agent", "Via", "Warn" };
572
573                 static string [] response_headers = new string [] {
574                         "Accept-Ranges", "Age", "Allow", "Cache-Control", "Content-Encoding", "Content-Language", 
575                         "Content-Length", "Content-Location", "Content-Disposition", "Content-MD5", "Content-Range", 
576                         "Content-Type", "Date", "ETag", "Expires", "Keep-Alive", "Last-Modified", "Location", "Pragma", 
577                         "Proxy-Authenticate", "Retry-After", "Server", "Set-Cookie", "Trailer", 
578                         "Transfer-Encoding", "Vary", "Via", "Warn", "WWW-Authenticate" };
579
580                 static string [] restricted_request_request = new string [] {
581                         "Accept", "Connection", "Content-Length", "Content-Type", "Date",
582                         "Expect", "Host", "If-Modified-Since", "Proxy-Connection", "Range", "Referer",
583                         "Transfer-Encoding", "User-Agent" };
584                 static string [] restricted_response_request = new string [] {
585                         "Content-Length", "Content-Type", "Date", "Transfer-Encoding" };
586
587                 static string [] restricted_request_response = new string [] {
588                          "Content-Length", "Transfer-Encoding" };
589                 static string [] restricted_response_response = new string [] {
590                          "Content-Length", "Keep-Alive", "Transfer-Encoding", "WWW-Authenticate" };
591
592                 [Test]
593                 public void IsRestricted_2_0_RequestRequest ()
594                 {
595                         int count = 0;
596                         foreach (string str in request_headers) {
597                                 if (WebHeaderCollection.IsRestricted (str, false)) {
598                                         Assert.IsTrue (Array.IndexOf (restricted_request_request, str) != -1, "restricted " + str);
599                                         count++;
600                                 } else {
601                                         Assert.IsTrue (Array.IndexOf (restricted_request_request, str) == -1, str);
602                                 }
603                         }
604                         Assert.IsTrue (count == restricted_request_request.Length, "req-req length");
605                 }
606
607                 [Test]
608                 public void IsRestricted_2_0_ResponseRequest ()
609                 {
610                         int count = 0;
611                         foreach (string str in response_headers) {
612                                 if (WebHeaderCollection.IsRestricted (str, false)) {
613                                         Assert.IsTrue (Array.IndexOf (restricted_response_request, str) != -1, "restricted " + str);
614                                         count++;
615                                 } else {
616                                         Assert.IsTrue (Array.IndexOf (restricted_response_request, str) == -1, str);
617                                 }
618                         }
619                         Assert.IsTrue (count == restricted_response_request.Length, "length");
620                 }
621
622                 [Test]
623                 public void IsRestricted_2_0_RequestResponse ()
624                 {
625                         int count = 0;
626                         foreach (string str in request_headers) {
627                                 if (WebHeaderCollection.IsRestricted (str, true)) {
628                                         Assert.IsTrue (Array.IndexOf (restricted_request_response, str) != -1, "restricted " + str);
629                                         count++;
630                                 } else {
631                                         Assert.IsTrue (Array.IndexOf (restricted_request_response, str) == -1, str);
632                                 }
633                         }
634                         Assert.IsTrue (count == restricted_request_response.Length, "length");
635                 }
636
637                 [Test]
638                 public void IsRestricted_2_0_ResponseResponse ()
639                 {
640                         int count = 0;
641                         foreach (string str in response_headers) {
642                                 if (WebHeaderCollection.IsRestricted (str, true)) {
643                                         Assert.IsTrue (Array.IndexOf (restricted_response_response, str) != -1, "restricted " + str);
644                                         count++;
645                                 } else {
646                                         Assert.IsTrue (Array.IndexOf (restricted_response_response, str) == -1, str);
647                                 }
648                         }
649                         Assert.IsTrue (count == restricted_response_response.Length, "length");
650                 }
651
652                 static WebHeaderCollection CreateRestrictedHeaders ()
653                 {
654                         var factory = Activator.CreateInstance (typeof (IWebRequestCreate).Assembly.GetType ("System.Net.HttpRequestCreator"), true) as IWebRequestCreate;
655                         return factory.Create (new Uri ("http://localhost")).Headers;
656                 }
657         }
658 }
659