mscorlib(4.0.0.0) API with additions
WebHeaderCollection.cs
1 using System.Collections;
8 using System.Text;
9 
10 namespace System.Net
11 {
13  [Serializable]
14  [ComVisible(true)]
15  [global::__DynamicallyInvokable]
17  {
18  internal static class HeaderEncoding
19  {
20  internal unsafe static string GetString(byte[] bytes, int byteIndex, int byteCount)
21  {
22  fixed (byte* ptr = bytes)
23  {
24  return GetString(ptr + byteIndex, byteCount);
25  }
26  }
27 
28  internal unsafe static string GetString(byte* pBytes, int byteCount)
29  {
30  if (byteCount < 1)
31  {
32  return "";
33  }
34  string text = new string('\0', byteCount);
35  fixed (char* ptr = text)
36  {
37  char* ptr2 = ptr;
38  while (byteCount >= 8)
39  {
40  *ptr2 = (char)(*pBytes);
41  ptr2[1] = (char)pBytes[1];
42  ptr2[2] = (char)pBytes[2];
43  ptr2[3] = (char)pBytes[3];
44  ptr2[4] = (char)pBytes[4];
45  ptr2[5] = (char)pBytes[5];
46  ptr2[6] = (char)pBytes[6];
47  ptr2[7] = (char)pBytes[7];
48  ptr2 += 8;
49  pBytes += 8;
50  byteCount -= 8;
51  }
52  for (int i = 0; i < byteCount; i++)
53  {
54  ptr2[i] = (char)pBytes[i];
55  }
56  }
57  return text;
58  }
59 
60  internal static int GetByteCount(string myString)
61  {
62  return myString.Length;
63  }
64 
65  internal unsafe static void GetBytes(string myString, int charIndex, int charCount, byte[] bytes, int byteIndex)
66  {
67  if (myString.Length != 0)
68  {
69  fixed (byte* ptr = bytes)
70  {
71  byte* ptr2 = ptr + byteIndex;
72  int num = charIndex + charCount;
73  while (charIndex < num)
74  {
75  byte* intPtr = ptr2;
76  ptr2 = intPtr + 1;
77  *intPtr = (byte)myString[charIndex++];
78  }
79  }
80  }
81  }
82 
83  internal static byte[] GetBytes(string myString)
84  {
85  byte[] array = new byte[myString.Length];
86  if (myString.Length != 0)
87  {
88  GetBytes(myString, 0, myString.Length, array, 0);
89  }
90  return array;
91  }
92 
93  [FriendAccessAllowed]
94  internal static string DecodeUtf8FromString(string input)
95  {
96  if (string.IsNullOrWhiteSpace(input))
97  {
98  return input;
99  }
100  bool flag = false;
101  for (int i = 0; i < input.Length; i++)
102  {
103  if (input[i] > 'ÿ')
104  {
105  return input;
106  }
107  if (input[i] > '\u007f')
108  {
109  flag = true;
110  break;
111  }
112  }
113  if (flag)
114  {
115  byte[] array = new byte[input.Length];
116  for (int j = 0; j < input.Length; j++)
117  {
118  if (input[j] > 'ÿ')
119  {
120  return input;
121  }
122  array[j] = (byte)input[j];
123  }
124  try
125  {
127  return encoding.GetString(array);
128  }
129  catch (ArgumentException)
130  {
131  return input;
132  }
133  }
134  return input;
135  }
136  }
137 
138  private enum RfcChar : byte
139  {
140  High,
141  Reg,
142  Ctl,
143  CR,
144  LF,
145  WS,
146  Colon,
147  Delim
148  }
149 
150  private const int ApproxAveHeaderLineSize = 30;
151 
152  private const int ApproxHighAvgNumHeaders = 16;
153 
154  private static readonly HeaderInfoTable HInfo = new HeaderInfoTable();
155 
156  private string[] m_CommonHeaders;
157 
158  private int m_NumCommonHeaders;
159 
160  private static readonly string[] s_CommonHeaderNames = new string[19]
161  {
162  "Accept-Ranges",
163  "Content-Length",
164  "Cache-Control",
165  "Content-Type",
166  "Date",
167  "Expires",
168  "ETag",
169  "Last-Modified",
170  "Location",
171  "Proxy-Authenticate",
172  "P3P",
173  "Set-Cookie2",
174  "Set-Cookie",
175  "Server",
176  "Via",
177  "WWW-Authenticate",
178  "X-AspNet-Version",
179  "X-Powered-By",
180  "["
181  };
182 
183  private static readonly sbyte[] s_CommonHeaderHints = new sbyte[32]
184  {
185  -1,
186  0,
187  -1,
188  1,
189  4,
190  5,
191  -1,
192  -1,
193  -1,
194  -1,
195  -1,
196  -1,
197  7,
198  -1,
199  -1,
200  -1,
201  9,
202  -1,
203  -1,
204  11,
205  -1,
206  -1,
207  14,
208  15,
209  16,
210  -1,
211  -1,
212  -1,
213  -1,
214  -1,
215  -1,
216  -1
217  };
218 
219  private const int c_AcceptRanges = 0;
220 
221  private const int c_ContentLength = 1;
222 
223  private const int c_CacheControl = 2;
224 
225  private const int c_ContentType = 3;
226 
227  private const int c_Date = 4;
228 
229  private const int c_Expires = 5;
230 
231  private const int c_ETag = 6;
232 
233  private const int c_LastModified = 7;
234 
235  private const int c_Location = 8;
236 
237  private const int c_ProxyAuthenticate = 9;
238 
239  private const int c_P3P = 10;
240 
241  private const int c_SetCookie2 = 11;
242 
243  private const int c_SetCookie = 12;
244 
245  private const int c_Server = 13;
246 
247  private const int c_Via = 14;
248 
249  private const int c_WwwAuthenticate = 15;
250 
251  private const int c_XAspNetVersion = 16;
252 
253  private const int c_XPoweredBy = 17;
254 
255  private NameValueCollection m_InnerCollection;
256 
257  private WebHeaderCollectionType m_Type;
258 
259  private static readonly char[] HttpTrimCharacters = new char[6]
260  {
261  '\t',
262  '\n',
263  '\v',
264  '\f',
265  '\r',
266  ' '
267  };
268 
269  private static RfcChar[] RfcCharMap = new RfcChar[128]
270  {
271  RfcChar.Ctl,
272  RfcChar.Ctl,
273  RfcChar.Ctl,
274  RfcChar.Ctl,
275  RfcChar.Ctl,
276  RfcChar.Ctl,
277  RfcChar.Ctl,
278  RfcChar.Ctl,
279  RfcChar.Ctl,
280  RfcChar.WS,
281  RfcChar.LF,
282  RfcChar.Ctl,
283  RfcChar.Ctl,
284  RfcChar.CR,
285  RfcChar.Ctl,
286  RfcChar.Ctl,
287  RfcChar.Ctl,
288  RfcChar.Ctl,
289  RfcChar.Ctl,
290  RfcChar.Ctl,
291  RfcChar.Ctl,
292  RfcChar.Ctl,
293  RfcChar.Ctl,
294  RfcChar.Ctl,
295  RfcChar.Ctl,
296  RfcChar.Ctl,
297  RfcChar.Ctl,
298  RfcChar.Ctl,
299  RfcChar.Ctl,
300  RfcChar.Ctl,
301  RfcChar.Ctl,
302  RfcChar.Ctl,
303  RfcChar.WS,
304  RfcChar.Reg,
305  RfcChar.Delim,
306  RfcChar.Reg,
307  RfcChar.Reg,
308  RfcChar.Reg,
309  RfcChar.Reg,
310  RfcChar.Reg,
311  RfcChar.Delim,
312  RfcChar.Delim,
313  RfcChar.Reg,
314  RfcChar.Reg,
315  RfcChar.Delim,
316  RfcChar.Reg,
317  RfcChar.Reg,
318  RfcChar.Delim,
319  RfcChar.Reg,
320  RfcChar.Reg,
321  RfcChar.Reg,
322  RfcChar.Reg,
323  RfcChar.Reg,
324  RfcChar.Reg,
325  RfcChar.Reg,
326  RfcChar.Reg,
327  RfcChar.Reg,
328  RfcChar.Reg,
329  RfcChar.Colon,
330  RfcChar.Delim,
331  RfcChar.Delim,
332  RfcChar.Delim,
333  RfcChar.Delim,
334  RfcChar.Delim,
335  RfcChar.Delim,
336  RfcChar.Reg,
337  RfcChar.Reg,
338  RfcChar.Reg,
339  RfcChar.Reg,
340  RfcChar.Reg,
341  RfcChar.Reg,
342  RfcChar.Reg,
343  RfcChar.Reg,
344  RfcChar.Reg,
345  RfcChar.Reg,
346  RfcChar.Reg,
347  RfcChar.Reg,
348  RfcChar.Reg,
349  RfcChar.Reg,
350  RfcChar.Reg,
351  RfcChar.Reg,
352  RfcChar.Reg,
353  RfcChar.Reg,
354  RfcChar.Reg,
355  RfcChar.Reg,
356  RfcChar.Reg,
357  RfcChar.Reg,
358  RfcChar.Reg,
359  RfcChar.Reg,
360  RfcChar.Reg,
361  RfcChar.Reg,
362  RfcChar.Delim,
363  RfcChar.Delim,
364  RfcChar.Delim,
365  RfcChar.Reg,
366  RfcChar.Reg,
367  RfcChar.Reg,
368  RfcChar.Reg,
369  RfcChar.Reg,
370  RfcChar.Reg,
371  RfcChar.Reg,
372  RfcChar.Reg,
373  RfcChar.Reg,
374  RfcChar.Reg,
375  RfcChar.Reg,
376  RfcChar.Reg,
377  RfcChar.Reg,
378  RfcChar.Reg,
379  RfcChar.Reg,
380  RfcChar.Reg,
381  RfcChar.Reg,
382  RfcChar.Reg,
383  RfcChar.Reg,
384  RfcChar.Reg,
385  RfcChar.Reg,
386  RfcChar.Reg,
387  RfcChar.Reg,
388  RfcChar.Reg,
389  RfcChar.Reg,
390  RfcChar.Reg,
391  RfcChar.Reg,
392  RfcChar.Reg,
393  RfcChar.Reg,
394  RfcChar.Delim,
395  RfcChar.Reg,
396  RfcChar.Delim,
397  RfcChar.Reg,
398  RfcChar.Ctl
399  };
400 
401  internal string ContentLength
402  {
403  get
404  {
405  if (m_CommonHeaders == null)
406  {
407  return Get(s_CommonHeaderNames[1]);
408  }
409  return m_CommonHeaders[1];
410  }
411  }
412 
413  internal string CacheControl
414  {
415  get
416  {
417  if (m_CommonHeaders == null)
418  {
419  return Get(s_CommonHeaderNames[2]);
420  }
421  return m_CommonHeaders[2];
422  }
423  }
424 
425  internal string ContentType
426  {
427  get
428  {
429  if (m_CommonHeaders == null)
430  {
431  return Get(s_CommonHeaderNames[3]);
432  }
433  return m_CommonHeaders[3];
434  }
435  }
436 
437  internal string Date
438  {
439  get
440  {
441  if (m_CommonHeaders == null)
442  {
443  return Get(s_CommonHeaderNames[4]);
444  }
445  return m_CommonHeaders[4];
446  }
447  }
448 
449  internal string Expires
450  {
451  get
452  {
453  if (m_CommonHeaders == null)
454  {
455  return Get(s_CommonHeaderNames[5]);
456  }
457  return m_CommonHeaders[5];
458  }
459  }
460 
461  internal string ETag
462  {
463  get
464  {
465  if (m_CommonHeaders == null)
466  {
467  return Get(s_CommonHeaderNames[6]);
468  }
469  return m_CommonHeaders[6];
470  }
471  }
472 
473  internal string LastModified
474  {
475  get
476  {
477  if (m_CommonHeaders == null)
478  {
479  return Get(s_CommonHeaderNames[7]);
480  }
481  return m_CommonHeaders[7];
482  }
483  }
484 
485  internal string Location
486  {
487  get
488  {
489  string input = (m_CommonHeaders != null) ? m_CommonHeaders[8] : Get(s_CommonHeaderNames[8]);
490  return HeaderEncoding.DecodeUtf8FromString(input);
491  }
492  }
493 
494  internal string ProxyAuthenticate
495  {
496  get
497  {
498  if (m_CommonHeaders == null)
499  {
500  return Get(s_CommonHeaderNames[9]);
501  }
502  return m_CommonHeaders[9];
503  }
504  }
505 
506  internal string SetCookie2
507  {
508  get
509  {
510  if (m_CommonHeaders == null)
511  {
512  return Get(s_CommonHeaderNames[11]);
513  }
514  return m_CommonHeaders[11];
515  }
516  }
517 
518  internal string SetCookie
519  {
520  get
521  {
522  if (m_CommonHeaders == null)
523  {
524  return Get(s_CommonHeaderNames[12]);
525  }
526  return m_CommonHeaders[12];
527  }
528  }
529 
530  internal string Server
531  {
532  get
533  {
534  if (m_CommonHeaders == null)
535  {
536  return Get(s_CommonHeaderNames[13]);
537  }
538  return m_CommonHeaders[13];
539  }
540  }
541 
542  internal string Via
543  {
544  get
545  {
546  if (m_CommonHeaders == null)
547  {
548  return Get(s_CommonHeaderNames[14]);
549  }
550  return m_CommonHeaders[14];
551  }
552  }
553 
554  private NameValueCollection InnerCollection
555  {
556  get
557  {
558  if (m_InnerCollection == null)
559  {
560  m_InnerCollection = new NameValueCollection(16, CaseInsensitiveAscii.StaticInstance);
561  }
562  return m_InnerCollection;
563  }
564  }
565 
566  private bool AllowHttpRequestHeader
567  {
568  get
569  {
570  if (m_Type == WebHeaderCollectionType.Unknown)
571  {
572  m_Type = WebHeaderCollectionType.WebRequest;
573  }
574  if (m_Type != WebHeaderCollectionType.WebRequest && m_Type != WebHeaderCollectionType.HttpWebRequest)
575  {
576  return m_Type == WebHeaderCollectionType.HttpListenerRequest;
577  }
578  return true;
579  }
580  }
581 
582  internal bool AllowHttpResponseHeader
583  {
584  get
585  {
586  if (m_Type == WebHeaderCollectionType.Unknown)
587  {
588  m_Type = WebHeaderCollectionType.WebResponse;
589  }
590  if (m_Type != WebHeaderCollectionType.WebResponse && m_Type != WebHeaderCollectionType.HttpWebResponse)
591  {
592  return m_Type == WebHeaderCollectionType.HttpListenerResponse;
593  }
594  return true;
595  }
596  }
597 
602  [global::__DynamicallyInvokable]
603  public string this[HttpRequestHeader header]
604  {
605  [global::__DynamicallyInvokable]
606  get
607  {
608  if (!AllowHttpRequestHeader)
609  {
610  throw new InvalidOperationException(SR.GetString("net_headers_req"));
611  }
612  return base[UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_HEADER_ID.ToString((int)header)];
613  }
614  [global::__DynamicallyInvokable]
615  set
616  {
617  if (!AllowHttpRequestHeader)
618  {
619  throw new InvalidOperationException(SR.GetString("net_headers_req"));
620  }
621  base[UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_HEADER_ID.ToString((int)header)] = value;
622  }
623  }
624 
630  [global::__DynamicallyInvokable]
631  public string this[HttpResponseHeader header]
632  {
633  [global::__DynamicallyInvokable]
634  get
635  {
636  if (!AllowHttpResponseHeader)
637  {
638  throw new InvalidOperationException(SR.GetString("net_headers_rsp"));
639  }
640  if (m_CommonHeaders != null)
641  {
642  switch (header)
643  {
644  case HttpResponseHeader.ProxyAuthenticate:
645  return m_CommonHeaders[9];
646  case HttpResponseHeader.WwwAuthenticate:
647  return m_CommonHeaders[15];
648  }
649  }
650  return base[UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header)];
651  }
652  [global::__DynamicallyInvokable]
653  set
654  {
655  if (!AllowHttpResponseHeader)
656  {
657  throw new InvalidOperationException(SR.GetString("net_headers_rsp"));
658  }
659  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && value != null && value.Length > 65535)
660  {
661  throw new ArgumentOutOfRangeException("value", value, SR.GetString("net_headers_toolong", ushort.MaxValue));
662  }
663  base[UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header)] = value;
664  }
665  }
666 
669  [global::__DynamicallyInvokable]
670  public override int Count
671  {
672  [global::__DynamicallyInvokable]
673  get
674  {
675  return ((m_InnerCollection != null) ? m_InnerCollection.Count : 0) + m_NumCommonHeaders;
676  }
677  }
678 
681  public override KeysCollection Keys
682  {
683  get
684  {
685  NormalizeCommonHeaders();
686  return InnerCollection.Keys;
687  }
688  }
689 
692  [global::__DynamicallyInvokable]
693  public override string[] AllKeys
694  {
695  [global::__DynamicallyInvokable]
696  get
697  {
698  NormalizeCommonHeaders();
699  return InnerCollection.AllKeys;
700  }
701  }
702 
703  private void NormalizeCommonHeaders()
704  {
705  if (m_CommonHeaders == null)
706  {
707  return;
708  }
709  for (int i = 0; i < m_CommonHeaders.Length; i++)
710  {
711  if (m_CommonHeaders[i] != null)
712  {
713  InnerCollection.Add(s_CommonHeaderNames[i], m_CommonHeaders[i]);
714  }
715  }
716  m_CommonHeaders = null;
717  m_NumCommonHeaders = 0;
718  }
719 
725  public void Add(HttpRequestHeader header, string value)
726  {
727  if (!AllowHttpRequestHeader)
728  {
729  throw new InvalidOperationException(SR.GetString("net_headers_req"));
730  }
731  Add(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_HEADER_ID.ToString((int)header), value);
732  }
733 
739  public void Add(HttpResponseHeader header, string value)
740  {
741  if (!AllowHttpResponseHeader)
742  {
743  throw new InvalidOperationException(SR.GetString("net_headers_rsp"));
744  }
745  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && value != null && value.Length > 65535)
746  {
747  throw new ArgumentOutOfRangeException("value", value, SR.GetString("net_headers_toolong", ushort.MaxValue));
748  }
749  Add(UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header), value);
750  }
751 
757  public void Set(HttpRequestHeader header, string value)
758  {
759  if (!AllowHttpRequestHeader)
760  {
761  throw new InvalidOperationException(SR.GetString("net_headers_req"));
762  }
763  Set(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_HEADER_ID.ToString((int)header), value);
764  }
765 
771  public void Set(HttpResponseHeader header, string value)
772  {
773  if (!AllowHttpResponseHeader)
774  {
775  throw new InvalidOperationException(SR.GetString("net_headers_rsp"));
776  }
777  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && value != null && value.Length > 65535)
778  {
779  throw new ArgumentOutOfRangeException("value", value, SR.GetString("net_headers_toolong", ushort.MaxValue));
780  }
781  Set(UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header), value);
782  }
783 
784  internal void SetInternal(HttpResponseHeader header, string value)
785  {
786  if (!AllowHttpResponseHeader)
787  {
788  throw new InvalidOperationException(SR.GetString("net_headers_rsp"));
789  }
790  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && value != null && value.Length > 65535)
791  {
792  throw new ArgumentOutOfRangeException("value", value, SR.GetString("net_headers_toolong", ushort.MaxValue));
793  }
794  SetInternal(UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header), value);
795  }
796 
800  public void Remove(HttpRequestHeader header)
801  {
802  if (!AllowHttpRequestHeader)
803  {
804  throw new InvalidOperationException(SR.GetString("net_headers_req"));
805  }
806  Remove(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_HEADER_ID.ToString((int)header));
807  }
808 
812  public void Remove(HttpResponseHeader header)
813  {
814  if (!AllowHttpResponseHeader)
815  {
816  throw new InvalidOperationException(SR.GetString("net_headers_rsp"));
817  }
818  Remove(UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header));
819  }
820 
829  protected void AddWithoutValidate(string headerName, string headerValue)
830  {
831  headerName = CheckBadChars(headerName, isHeaderValue: false);
832  headerValue = CheckBadChars(headerValue, isHeaderValue: true);
833  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && headerValue != null && headerValue.Length > 65535)
834  {
835  throw new ArgumentOutOfRangeException("headerValue", headerValue, SR.GetString("net_headers_toolong", ushort.MaxValue));
836  }
837  NormalizeCommonHeaders();
839  InnerCollection.Add(headerName, headerValue);
840  }
841 
842  internal void SetAddVerified(string name, string value)
843  {
844  if (HInfo[name].AllowMultiValues)
845  {
846  NormalizeCommonHeaders();
848  InnerCollection.Add(name, value);
849  }
850  else
851  {
852  NormalizeCommonHeaders();
854  InnerCollection.Set(name, value);
855  }
856  }
857 
858  internal void AddInternal(string name, string value)
859  {
860  NormalizeCommonHeaders();
862  InnerCollection.Add(name, value);
863  }
864 
865  internal void ChangeInternal(string name, string value)
866  {
867  NormalizeCommonHeaders();
869  InnerCollection.Set(name, value);
870  }
871 
872  internal void RemoveInternal(string name)
873  {
874  NormalizeCommonHeaders();
875  if (m_InnerCollection != null)
876  {
878  m_InnerCollection.Remove(name);
879  }
880  }
881 
882  internal void CheckUpdate(string name, string value)
883  {
884  value = CheckBadChars(value, isHeaderValue: true);
885  ChangeInternal(name, value);
886  }
887 
888  private void AddInternalNotCommon(string name, string value)
889  {
891  InnerCollection.Add(name, value);
892  }
893 
894  internal static string CheckBadChars(string name, bool isHeaderValue)
895  {
896  if (name == null || name.Length == 0)
897  {
898  if (!isHeaderValue)
899  {
900  throw (name == null) ? new ArgumentNullException("name") : new ArgumentException(SR.GetString("net_emptystringcall", "name"), "name");
901  }
902  return string.Empty;
903  }
904  if (isHeaderValue)
905  {
906  name = name.Trim(HttpTrimCharacters);
907  int num = 0;
908  for (int i = 0; i < name.Length; i++)
909  {
910  char c = (char)(0xFF & name[i]);
911  switch (num)
912  {
913  case 0:
914  if (c == '\r')
915  {
916  num = 1;
917  }
918  else if (c == '\n')
919  {
920  num = 2;
921  }
922  else if (c == '\u007f' || (c < ' ' && c != '\t'))
923  {
924  throw new ArgumentException(SR.GetString("net_WebHeaderInvalidControlChars"), "value");
925  }
926  break;
927  case 1:
928  if (c == '\n')
929  {
930  num = 2;
931  break;
932  }
933  throw new ArgumentException(SR.GetString("net_WebHeaderInvalidCRLFChars"), "value");
934  case 2:
935  if (c == ' ' || c == '\t')
936  {
937  num = 0;
938  break;
939  }
940  throw new ArgumentException(SR.GetString("net_WebHeaderInvalidCRLFChars"), "value");
941  }
942  }
943  if (num != 0)
944  {
945  throw new ArgumentException(SR.GetString("net_WebHeaderInvalidCRLFChars"), "value");
946  }
947  }
948  else
949  {
950  if (name.IndexOfAny(ValidationHelper.InvalidParamChars) != -1)
951  {
952  throw new ArgumentException(SR.GetString("net_WebHeaderInvalidHeaderChars"), "name");
953  }
954  if (ContainsNonAsciiChars(name))
955  {
956  throw new ArgumentException(SR.GetString("net_WebHeaderInvalidNonAsciiChars"), "name");
957  }
958  }
959  return name;
960  }
961 
962  internal static bool IsValidToken(string token)
963  {
964  if (token.Length > 0 && token.IndexOfAny(ValidationHelper.InvalidParamChars) == -1)
965  {
966  return !ContainsNonAsciiChars(token);
967  }
968  return false;
969  }
970 
971  internal static bool ContainsNonAsciiChars(string token)
972  {
973  for (int i = 0; i < token.Length; i++)
974  {
975  if (token[i] < ' ' || token[i] > '~')
976  {
977  return true;
978  }
979  }
980  return false;
981  }
982 
983  internal void ThrowOnRestrictedHeader(string headerName)
984  {
985  if (m_Type == WebHeaderCollectionType.HttpWebRequest)
986  {
987  if (HInfo[headerName].IsRequestRestricted)
988  {
989  throw new ArgumentException(SR.GetString("net_headerrestrict", headerName), "name");
990  }
991  }
992  else if (m_Type == WebHeaderCollectionType.HttpListenerResponse && HInfo[headerName].IsResponseRestricted)
993  {
994  throw new ArgumentException(SR.GetString("net_headerrestrict", headerName), "name");
995  }
996  }
997 
1006  public override void Add(string name, string value)
1007  {
1008  name = CheckBadChars(name, isHeaderValue: false);
1009  ThrowOnRestrictedHeader(name);
1010  value = CheckBadChars(value, isHeaderValue: true);
1011  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && value != null && value.Length > 65535)
1012  {
1013  throw new ArgumentOutOfRangeException("value", value, SR.GetString("net_headers_toolong", ushort.MaxValue));
1014  }
1015  NormalizeCommonHeaders();
1017  InnerCollection.Add(name, value);
1018  }
1019 
1028  public void Add(string header)
1029  {
1030  if (ValidationHelper.IsBlankString(header))
1031  {
1032  throw new ArgumentNullException("header");
1033  }
1034  int num = header.IndexOf(':');
1035  if (num < 0)
1036  {
1037  throw new ArgumentException(SR.GetString("net_WebHeaderMissingColon"), "header");
1038  }
1039  string name = header.Substring(0, num);
1040  string name2 = header.Substring(num + 1);
1041  name = CheckBadChars(name, isHeaderValue: false);
1042  ThrowOnRestrictedHeader(name);
1043  name2 = CheckBadChars(name2, isHeaderValue: true);
1044  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && name2 != null && name2.Length > 65535)
1045  {
1046  throw new ArgumentOutOfRangeException("value", name2, SR.GetString("net_headers_toolong", ushort.MaxValue));
1047  }
1048  NormalizeCommonHeaders();
1050  InnerCollection.Add(name, name2);
1051  }
1052 
1062  public override void Set(string name, string value)
1063  {
1064  if (ValidationHelper.IsBlankString(name))
1065  {
1066  throw new ArgumentNullException("name");
1067  }
1068  name = CheckBadChars(name, isHeaderValue: false);
1069  ThrowOnRestrictedHeader(name);
1070  value = CheckBadChars(value, isHeaderValue: true);
1071  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && value != null && value.Length > 65535)
1072  {
1073  throw new ArgumentOutOfRangeException("value", value, SR.GetString("net_headers_toolong", ushort.MaxValue));
1074  }
1075  NormalizeCommonHeaders();
1077  InnerCollection.Set(name, value);
1078  }
1079 
1080  internal void SetInternal(string name, string value)
1081  {
1082  if (ValidationHelper.IsBlankString(name))
1083  {
1084  throw new ArgumentNullException("name");
1085  }
1086  name = CheckBadChars(name, isHeaderValue: false);
1087  value = CheckBadChars(value, isHeaderValue: true);
1088  if (m_Type == WebHeaderCollectionType.HttpListenerResponse && value != null && value.Length > 65535)
1089  {
1090  throw new ArgumentOutOfRangeException("value", value, SR.GetString("net_headers_toolong", ushort.MaxValue));
1091  }
1092  NormalizeCommonHeaders();
1094  InnerCollection.Set(name, value);
1095  }
1096 
1104  [global::__DynamicallyInvokable]
1105  public override void Remove(string name)
1106  {
1107  if (ValidationHelper.IsBlankString(name))
1108  {
1109  throw new ArgumentNullException("name");
1110  }
1111  ThrowOnRestrictedHeader(name);
1112  name = CheckBadChars(name, isHeaderValue: false);
1113  NormalizeCommonHeaders();
1114  if (m_InnerCollection != null)
1115  {
1117  m_InnerCollection.Remove(name);
1118  }
1119  }
1120 
1124  public override string[] GetValues(string header)
1125  {
1126  NormalizeCommonHeaders();
1127  HeaderInfo headerInfo = HInfo[header];
1128  string[] values = InnerCollection.GetValues(header);
1129  if (headerInfo == null || values == null || !headerInfo.AllowMultiValues)
1130  {
1131  return values;
1132  }
1133  ArrayList arrayList = null;
1134  for (int i = 0; i < values.Length; i++)
1135  {
1136  string[] array = headerInfo.Parser(values[i]);
1137  if (arrayList == null)
1138  {
1139  if (array.Length > 1)
1140  {
1141  arrayList = new ArrayList(values);
1142  arrayList.RemoveRange(i, values.Length - i);
1143  arrayList.AddRange(array);
1144  }
1145  }
1146  else
1147  {
1148  arrayList.AddRange(array);
1149  }
1150  }
1151  if (arrayList != null)
1152  {
1153  string[] array2 = new string[arrayList.Count];
1154  arrayList.CopyTo(array2);
1155  return array2;
1156  }
1157  return values;
1158  }
1159 
1162  [global::__DynamicallyInvokable]
1163  public override string ToString()
1164  {
1165  return GetAsString(this, winInetCompat: false, forTrace: false);
1166  }
1167 
1168  internal string ToString(bool forTrace)
1169  {
1170  return GetAsString(this, winInetCompat: false, forTrace: true);
1171  }
1172 
1173  internal static string GetAsString(NameValueCollection cc, bool winInetCompat, bool forTrace)
1174  {
1175  if (cc == null || cc.Count == 0)
1176  {
1177  return "\r\n";
1178  }
1179  StringBuilder stringBuilder = new StringBuilder(30 * cc.Count);
1180  string text = cc[string.Empty];
1181  if (text != null)
1182  {
1183  stringBuilder.Append(text).Append("\r\n");
1184  }
1185  for (int i = 0; i < cc.Count; i++)
1186  {
1187  string key = cc.GetKey(i);
1188  string value = cc.Get(i);
1189  if (!ValidationHelper.IsBlankString(key))
1190  {
1191  stringBuilder.Append(key);
1192  if (winInetCompat)
1193  {
1194  stringBuilder.Append(':');
1195  }
1196  else
1197  {
1198  stringBuilder.Append(": ");
1199  }
1200  stringBuilder.Append(value).Append("\r\n");
1201  }
1202  }
1203  if (!forTrace)
1204  {
1205  stringBuilder.Append("\r\n");
1206  }
1207  return stringBuilder.ToString();
1208  }
1209 
1212  public byte[] ToByteArray()
1213  {
1214  string myString = ToString();
1215  return HeaderEncoding.GetBytes(myString);
1216  }
1217 
1226  public static bool IsRestricted(string headerName)
1227  {
1228  return IsRestricted(headerName, response: false);
1229  }
1230 
1240  public static bool IsRestricted(string headerName, bool response)
1241  {
1242  if (!response)
1243  {
1244  return HInfo[CheckBadChars(headerName, isHeaderValue: false)].IsRequestRestricted;
1245  }
1246  return HInfo[CheckBadChars(headerName, isHeaderValue: false)].IsResponseRestricted;
1247  }
1248 
1250  [global::__DynamicallyInvokable]
1252  : base(DBNull.Value)
1253  {
1254  }
1255 
1256  internal WebHeaderCollection(WebHeaderCollectionType type)
1257  : base(DBNull.Value)
1258  {
1259  m_Type = type;
1260  if (type == WebHeaderCollectionType.HttpWebResponse)
1261  {
1262  m_CommonHeaders = new string[s_CommonHeaderNames.Length - 1];
1263  }
1264  }
1265 
1267  : base(DBNull.Value)
1268  {
1269  m_InnerCollection = new NameValueCollection(cc.Count + 2, CaseInsensitiveAscii.StaticInstance);
1270  int count = cc.Count;
1271  for (int i = 0; i < count; i++)
1272  {
1273  string key = cc.GetKey(i);
1274  string[] values = cc.GetValues(i);
1275  if (values != null)
1276  {
1277  for (int j = 0; j < values.Length; j++)
1278  {
1279  InnerCollection.Add(key, values[j]);
1280  }
1281  }
1282  else
1283  {
1284  InnerCollection.Add(key, null);
1285  }
1286  }
1287  }
1288 
1296  protected WebHeaderCollection(SerializationInfo serializationInfo, StreamingContext streamingContext)
1297  : base(DBNull.Value)
1298  {
1299  int @int = serializationInfo.GetInt32("Count");
1300  m_InnerCollection = new NameValueCollection(@int + 2, CaseInsensitiveAscii.StaticInstance);
1301  for (int i = 0; i < @int; i++)
1302  {
1303  string @string = serializationInfo.GetString(i.ToString(NumberFormatInfo.InvariantInfo));
1304  string string2 = serializationInfo.GetString((i + @int).ToString(NumberFormatInfo.InvariantInfo));
1305  InnerCollection.Add(@string, string2);
1306  }
1307  }
1308 
1311  public override void OnDeserialization(object sender)
1312  {
1313  }
1314 
1318  [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
1319  public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
1320  {
1321  NormalizeCommonHeaders();
1322  serializationInfo.AddValue("Count", Count);
1323  for (int i = 0; i < Count; i++)
1324  {
1325  serializationInfo.AddValue(i.ToString(NumberFormatInfo.InvariantInfo), GetKey(i));
1326  serializationInfo.AddValue((i + Count).ToString(NumberFormatInfo.InvariantInfo), Get(i));
1327  }
1328  }
1329 
1330  internal unsafe DataParseStatus ParseHeaders(byte[] buffer, int size, ref int unparsed, ref int totalResponseHeadersLength, int maximumResponseHeadersLength, ref WebParseError parseError)
1331  {
1332  fixed (byte* ptr = buffer)
1333  {
1334  if (buffer.Length < size)
1335  {
1336  return DataParseStatus.NeedMoreData;
1337  }
1338  int num = -1;
1339  int num2 = -1;
1340  int num3 = -1;
1341  int num4 = -1;
1342  int num5 = -1;
1343  int num6 = unparsed;
1344  int num7 = totalResponseHeadersLength;
1345  WebParseErrorCode code = WebParseErrorCode.Generic;
1346  DataParseStatus dataParseStatus = DataParseStatus.Invalid;
1347  while (true)
1348  {
1349  string text = string.Empty;
1350  string text2 = string.Empty;
1351  bool flag = false;
1352  string text3 = null;
1353  char c;
1354  if (Count == 0)
1355  {
1356  while (num6 < size)
1357  {
1358  c = (char)ptr[num6];
1359  if (c != ' ' && c != '\t')
1360  {
1361  break;
1362  }
1363  num6++;
1364  if (maximumResponseHeadersLength < 0 || ++num7 < maximumResponseHeadersLength)
1365  {
1366  continue;
1367  }
1368  goto IL_0081;
1369  }
1370  if (num6 == size)
1371  {
1372  dataParseStatus = DataParseStatus.NeedMoreData;
1373  break;
1374  }
1375  }
1376  num = num6;
1377  while (num6 < size)
1378  {
1379  c = (char)ptr[num6];
1380  if (c != ':' && c != '\n')
1381  {
1382  if (c > ' ')
1383  {
1384  num2 = num6;
1385  }
1386  num6++;
1387  if (maximumResponseHeadersLength < 0 || ++num7 < maximumResponseHeadersLength)
1388  {
1389  continue;
1390  }
1391  goto IL_00d0;
1392  }
1393  goto IL_00d8;
1394  }
1395  goto IL_0100;
1396  IL_02cc:
1397  dataParseStatus = DataParseStatus.DataTooBig;
1398  break;
1399  IL_0145:
1400  dataParseStatus = DataParseStatus.NeedMoreData;
1401  break;
1402  IL_0180:
1403  dataParseStatus = DataParseStatus.DataTooBig;
1404  break;
1405  IL_0081:
1406  dataParseStatus = DataParseStatus.DataTooBig;
1407  break;
1408  IL_0251:
1409  dataParseStatus = DataParseStatus.NeedMoreData;
1410  break;
1411  IL_02d1:
1412  if (num >= 0 && num2 >= num)
1413  {
1414  text = HeaderEncoding.GetString(ptr + num, num2 - num + 1);
1415  }
1416  if (text.Length > 0)
1417  {
1418  AddInternal(text, text3);
1419  }
1420  totalResponseHeadersLength = num7;
1421  unparsed = num6;
1422  if (num5 == 2)
1423  {
1424  dataParseStatus = DataParseStatus.Done;
1425  break;
1426  }
1427  continue;
1428  IL_00d0:
1429  dataParseStatus = DataParseStatus.DataTooBig;
1430  break;
1431  IL_00d8:
1432  if (c == ':')
1433  {
1434  num6++;
1435  if (maximumResponseHeadersLength >= 0 && ++num7 >= maximumResponseHeadersLength)
1436  {
1437  dataParseStatus = DataParseStatus.DataTooBig;
1438  break;
1439  }
1440  }
1441  goto IL_0100;
1442  IL_01e4:
1443  dataParseStatus = DataParseStatus.DataTooBig;
1444  break;
1445  IL_01f6:
1446  dataParseStatus = DataParseStatus.NeedMoreData;
1447  break;
1448  IL_0235:
1449  dataParseStatus = DataParseStatus.DataTooBig;
1450  break;
1451  IL_0100:
1452  if (num6 == size)
1453  {
1454  dataParseStatus = DataParseStatus.NeedMoreData;
1455  }
1456  else
1457  {
1458  while (true)
1459  {
1460  num5 = ((Count == 0 && num2 < 0) ? 1 : 0);
1461  while (num6 < size && num5 < 2)
1462  {
1463  c = (char)ptr[num6];
1464  if (c > ' ')
1465  {
1466  break;
1467  }
1468  if (c == '\n')
1469  {
1470  num5++;
1471  if (num5 == 1)
1472  {
1473  if (num6 + 1 == size)
1474  {
1475  goto IL_0145;
1476  }
1477  flag = (ptr[num6 + 1] == 32 || ptr[num6 + 1] == 9);
1478  }
1479  }
1480  num6++;
1481  if (maximumResponseHeadersLength < 0 || ++num7 < maximumResponseHeadersLength)
1482  {
1483  continue;
1484  }
1485  goto IL_0180;
1486  }
1487  if (num5 != 2 && (num5 != 1 || flag))
1488  {
1489  if (num6 == size)
1490  {
1491  break;
1492  }
1493  num3 = num6;
1494  while (num6 < size)
1495  {
1496  c = (char)ptr[num6];
1497  if (c == '\n')
1498  {
1499  break;
1500  }
1501  if (c > ' ')
1502  {
1503  num4 = num6;
1504  }
1505  num6++;
1506  if (maximumResponseHeadersLength < 0 || ++num7 < maximumResponseHeadersLength)
1507  {
1508  continue;
1509  }
1510  goto IL_01e4;
1511  }
1512  if (num6 == size)
1513  {
1514  goto IL_01f6;
1515  }
1516  num5 = 0;
1517  while (num6 < size && num5 < 2)
1518  {
1519  c = (char)ptr[num6];
1520  if (c != '\r' && c != '\n')
1521  {
1522  break;
1523  }
1524  if (c == '\n')
1525  {
1526  num5++;
1527  }
1528  num6++;
1529  if (maximumResponseHeadersLength < 0 || ++num7 < maximumResponseHeadersLength)
1530  {
1531  continue;
1532  }
1533  goto IL_0235;
1534  }
1535  if (num6 == size && num5 < 2)
1536  {
1537  goto IL_0251;
1538  }
1539  }
1540  if (num3 >= 0 && num3 > num2 && num4 >= num3)
1541  {
1542  text2 = HeaderEncoding.GetString(ptr + num3, num4 - num3 + 1);
1543  }
1544  text3 = ((text3 == null) ? text2 : (text3 + " " + text2));
1545  if (num6 < size && num5 == 1)
1546  {
1547  c = (char)ptr[num6];
1548  if (c == ' ' || c == '\t')
1549  {
1550  num6++;
1551  if (maximumResponseHeadersLength < 0 || ++num7 < maximumResponseHeadersLength)
1552  {
1553  continue;
1554  }
1555  goto IL_02cc;
1556  }
1557  }
1558  goto IL_02d1;
1559  }
1560  dataParseStatus = DataParseStatus.NeedMoreData;
1561  }
1562  break;
1563  }
1564  if (dataParseStatus == DataParseStatus.Invalid)
1565  {
1566  parseError.Section = WebParseErrorSection.ResponseHeader;
1567  parseError.Code = code;
1568  }
1569  return dataParseStatus;
1570  }
1571  }
1572 
1573  internal unsafe DataParseStatus ParseHeadersStrict(byte[] buffer, int size, ref int unparsed, ref int totalResponseHeadersLength, int maximumResponseHeadersLength, ref WebParseError parseError)
1574  {
1575  WebParseErrorCode code = WebParseErrorCode.Generic;
1576  DataParseStatus dataParseStatus = DataParseStatus.Invalid;
1577  int i = unparsed;
1578  int num = (maximumResponseHeadersLength <= 0) ? int.MaxValue : (maximumResponseHeadersLength - totalResponseHeadersLength + i);
1579  DataParseStatus dataParseStatus2 = DataParseStatus.DataTooBig;
1580  if (size < num)
1581  {
1582  num = size;
1583  dataParseStatus2 = DataParseStatus.NeedMoreData;
1584  }
1585  if (i >= num)
1586  {
1587  dataParseStatus = dataParseStatus2;
1588  }
1589  else
1590  {
1591  try
1592  {
1593  fixed (byte* ptr = buffer)
1594  {
1595  while (true)
1596  {
1597  IL_0055:
1598  if (ptr[i] == 13)
1599  {
1600  if (++i == num)
1601  {
1602  dataParseStatus = dataParseStatus2;
1603  }
1604  else if (ptr[i++] == 10)
1605  {
1606  totalResponseHeadersLength += i - unparsed;
1607  unparsed = i;
1608  dataParseStatus = DataParseStatus.Done;
1609  }
1610  else
1611  {
1612  dataParseStatus = DataParseStatus.Invalid;
1613  code = WebParseErrorCode.CrLfError;
1614  }
1615  }
1616  else
1617  {
1618  int num3 = i;
1619  for (; i < num; i++)
1620  {
1621  RfcChar rfcChar;
1622  if ((rfcChar = ((ptr[i] <= 127) ? RfcCharMap[ptr[i]] : RfcChar.High)) != RfcChar.Reg)
1623  {
1624  break;
1625  }
1626  }
1627  if (i == num)
1628  {
1629  dataParseStatus = dataParseStatus2;
1630  }
1631  else if (i == num3)
1632  {
1633  dataParseStatus = DataParseStatus.Invalid;
1634  code = WebParseErrorCode.InvalidHeaderName;
1635  }
1636  else
1637  {
1638  int num4 = i - 1;
1639  int num5 = 0;
1640  while (true)
1641  {
1642  RfcChar rfcChar;
1643  if (i < num && (rfcChar = ((ptr[i] <= 127) ? RfcCharMap[ptr[i]] : RfcChar.High)) != RfcChar.Colon)
1644  {
1645  switch (rfcChar)
1646  {
1647  case RfcChar.WS:
1648  if (num5 != 1)
1649  {
1650  num5 = 0;
1651  goto IL_0129;
1652  }
1653  break;
1654  case RfcChar.CR:
1655  if (num5 == 0)
1656  {
1657  num5 = 1;
1658  goto IL_0129;
1659  }
1660  break;
1661  case RfcChar.LF:
1662  if (num5 == 1)
1663  {
1664  num5 = 2;
1665  goto IL_0129;
1666  }
1667  break;
1668  }
1669  dataParseStatus = DataParseStatus.Invalid;
1670  code = WebParseErrorCode.CrLfError;
1671  }
1672  else if (i == num)
1673  {
1674  dataParseStatus = dataParseStatus2;
1675  }
1676  else if (num5 != 0)
1677  {
1678  dataParseStatus = DataParseStatus.Invalid;
1679  code = WebParseErrorCode.IncompleteHeaderLine;
1680  }
1681  else if (++i == num)
1682  {
1683  dataParseStatus = dataParseStatus2;
1684  }
1685  else
1686  {
1687  int num6 = -1;
1688  int num7 = -1;
1689  StringBuilder stringBuilder = null;
1690  while (true)
1691  {
1692  if (i < num && ((rfcChar = ((ptr[i] <= 127) ? RfcCharMap[ptr[i]] : RfcChar.High)) == RfcChar.WS || num5 != 2))
1693  {
1694  switch (rfcChar)
1695  {
1696  case RfcChar.WS:
1697  switch (num5)
1698  {
1699  case 2:
1700  num5 = 3;
1701  goto IL_024d;
1702  case 1:
1703  break;
1704  default:
1705  goto IL_024d;
1706  }
1707  break;
1708  case RfcChar.CR:
1709  if (num5 == 0)
1710  {
1711  num5 = 1;
1712  goto IL_024d;
1713  }
1714  break;
1715  case RfcChar.LF:
1716  if (num5 == 1)
1717  {
1718  num5 = 2;
1719  goto IL_024d;
1720  }
1721  break;
1722  case RfcChar.High:
1723  case RfcChar.Reg:
1724  case RfcChar.Colon:
1725  case RfcChar.Delim:
1726  if (num5 != 1)
1727  {
1728  if (num5 == 3)
1729  {
1730  num5 = 0;
1731  if (num6 != -1)
1732  {
1733  string @string = HeaderEncoding.GetString(ptr + num6, num7 - num6 + 1);
1734  if (stringBuilder == null)
1735  {
1736  stringBuilder = new StringBuilder(@string, @string.Length * 5);
1737  }
1738  else
1739  {
1740  stringBuilder.Append(" ");
1741  stringBuilder.Append(@string);
1742  }
1743  }
1744  num6 = -1;
1745  }
1746  if (num6 == -1)
1747  {
1748  num6 = i;
1749  }
1750  num7 = i;
1751  goto IL_024d;
1752  }
1753  break;
1754  }
1755  dataParseStatus = DataParseStatus.Invalid;
1756  code = WebParseErrorCode.CrLfError;
1757  break;
1758  }
1759  if (i == num)
1760  {
1761  dataParseStatus = dataParseStatus2;
1762  break;
1763  }
1764  string text = (num6 == -1) ? "" : HeaderEncoding.GetString(ptr + num6, num7 - num6 + 1);
1765  if (stringBuilder != null)
1766  {
1767  if (text.Length != 0)
1768  {
1769  stringBuilder.Append(" ");
1770  stringBuilder.Append(text);
1771  }
1772  text = stringBuilder.ToString();
1773  }
1774  string text2 = null;
1775  int num8 = num4 - num3 + 1;
1776  if (m_CommonHeaders != null)
1777  {
1778  int num9 = s_CommonHeaderHints[ptr[num3] & 0x1F];
1779  if (num9 >= 0)
1780  {
1781  while (true)
1782  {
1783  string text3 = s_CommonHeaderNames[num9++];
1784  if (text3.Length < num8 || CaseInsensitiveAscii.AsciiToLower[ptr[num3]] != CaseInsensitiveAscii.AsciiToLower[text3[0]])
1785  {
1786  break;
1787  }
1788  if (text3.Length <= num8)
1789  {
1790  byte* ptr2 = ptr + num3 + 1;
1791  int j;
1792  for (j = 1; j < text3.Length; j++)
1793  {
1794  byte* intPtr = ptr2;
1795  ptr2 = intPtr + 1;
1796  if (*intPtr != text3[j] && CaseInsensitiveAscii.AsciiToLower[*(ptr2 - 1)] != CaseInsensitiveAscii.AsciiToLower[text3[j]])
1797  {
1798  break;
1799  }
1800  }
1801  if (j == text3.Length)
1802  {
1803  m_NumCommonHeaders++;
1804  num9--;
1805  if (m_CommonHeaders[num9] == null)
1806  {
1807  m_CommonHeaders[num9] = text;
1808  }
1809  else
1810  {
1811  NormalizeCommonHeaders();
1812  AddInternalNotCommon(text3, text);
1813  }
1814  text2 = text3;
1815  break;
1816  }
1817  }
1818  }
1819  }
1820  }
1821  if (text2 == null)
1822  {
1823  text2 = HeaderEncoding.GetString(ptr + num3, num8);
1824  AddInternalNotCommon(text2, text);
1825  }
1826  totalResponseHeadersLength += i - unparsed;
1827  unparsed = i;
1828  goto IL_0055;
1829  IL_024d:
1830  i++;
1831  }
1832  }
1833  break;
1834  IL_0129:
1835  i++;
1836  }
1837  }
1838  }
1839  break;
1840  }
1841  }
1842  }
1843  finally
1844  {
1845  }
1846  }
1847  if (dataParseStatus == DataParseStatus.Invalid)
1848  {
1849  parseError.Section = WebParseErrorSection.ResponseHeader;
1850  parseError.Code = code;
1851  }
1852  return dataParseStatus;
1853  }
1854 
1858  [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter, SerializationFormatter = true)]
1859  void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
1860  {
1861  GetObjectData(serializationInfo, streamingContext);
1862  }
1863 
1867  public override string Get(string name)
1868  {
1869  if (m_CommonHeaders != null && name != null && name.Length > 0 && name[0] < 'Ā')
1870  {
1871  int num = s_CommonHeaderHints[name[0] & 0x1F];
1872  if (num >= 0)
1873  {
1874  while (true)
1875  {
1876  string text = s_CommonHeaderNames[num++];
1877  if (text.Length < name.Length || CaseInsensitiveAscii.AsciiToLower[name[0]] != CaseInsensitiveAscii.AsciiToLower[text[0]])
1878  {
1879  break;
1880  }
1881  if (text.Length <= name.Length)
1882  {
1883  int i;
1884  for (i = 1; i < text.Length && (name[i] == text[i] || (name[i] <= 'ÿ' && CaseInsensitiveAscii.AsciiToLower[name[i]] == CaseInsensitiveAscii.AsciiToLower[text[i]])); i++)
1885  {
1886  }
1887  if (i == text.Length)
1888  {
1889  return m_CommonHeaders[num - 1];
1890  }
1891  }
1892  }
1893  }
1894  }
1895  if (m_InnerCollection == null)
1896  {
1897  return null;
1898  }
1899  return m_InnerCollection.Get(name);
1900  }
1901 
1904  public override IEnumerator GetEnumerator()
1905  {
1906  NormalizeCommonHeaders();
1907  return new NameObjectKeysEnumerator(InnerCollection);
1908  }
1909 
1910  internal override bool InternalHasKeys()
1911  {
1912  NormalizeCommonHeaders();
1913  if (m_InnerCollection == null)
1914  {
1915  return false;
1916  }
1917  return m_InnerCollection.HasKeys();
1918  }
1919 
1926  public override string Get(int index)
1927  {
1928  NormalizeCommonHeaders();
1929  return InnerCollection.Get(index);
1930  }
1931 
1935  public override string[] GetValues(int index)
1936  {
1937  NormalizeCommonHeaders();
1938  return InnerCollection.GetValues(index);
1939  }
1940 
1947  public override string GetKey(int index)
1948  {
1949  NormalizeCommonHeaders();
1950  return InnerCollection.GetKey(index);
1951  }
1952 
1954  public override void Clear()
1955  {
1956  m_CommonHeaders = null;
1957  m_NumCommonHeaders = 0;
1959  if (m_InnerCollection != null)
1960  {
1961  m_InnerCollection.Clear();
1962  }
1963  }
1964  }
1965 }
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
virtual string Get(string name)
Gets the values associated with the specified key from the T:System.Collections.Specialized....
override string ToString()
This method is obsolete.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
unsafe string GetString(byte *bytes, int byteCount)
When overridden in a derived class, decodes a specified number of bytes starting at a specified addre...
Definition: Encoding.cs:1918
Represents a collection of associated T:System.String keys and T:System.String values that can be acc...
override string [] GetValues(string header)
Gets an array of header values stored in a header.
override void Clear()
Removes all headers from the collection.
void Set(HttpRequestHeader header, string value)
Sets the specified header to the specified value.
virtual void Clear()
Invalidates the cached arrays and removes all entries from the T:System.Collections....
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
bool HasKeys()
Gets a value indicating whether the T:System.Collections.Specialized.NameValueCollection contains key...
virtual string [] AllKeys
Gets all the keys in the T:System.Collections.Specialized.NameValueCollection.
override int? Count
Gets the number of headers in the collection.
override void Add(string name, string value)
Inserts a header with the specified name and value into the collection.
virtual void Remove(string name)
Removes the entries with the specified key from the T:System.Collections.Specialized....
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2255
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
void Add(HttpRequestHeader header, string value)
Inserts the specified header with the specified value into the collection.
void AddWithoutValidate(string headerName, string headerValue)
Inserts a header into the collection without checking whether the header is on the restricted header ...
static DecoderFallback ExceptionFallback
Gets an object that throws an exception when an input byte sequence cannot be decoded.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
static Encoding GetEncoding(int codepage)
Returns the encoding associated with the specified code page identifier.
Definition: Encoding.cs:1249
Provides a failure-handling mechanism, called a fallback, for an input character that cannot be conve...
Contains protocol headers associated with a request or response.
override IEnumerator GetEnumerator()
Returns an enumerator that can iterate through the T:System.Net.WebHeaderCollection instance.
override string Get(int index)
Gets the value of a particular header in the collection, specified by an index into the collection.
SecurityAction
Specifies the security actions that can be performed using declarative security.
static bool IsRestricted(string headerName)
Tests whether the specified HTTP header can be set for the request.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
void AddValue(string name, object value, Type type)
Adds a value into the T:System.Runtime.Serialization.SerializationInfo store, where value is associa...
virtual string [] GetValues(string name)
Gets the values associated with the specified key from the T:System.Collections.Specialized....
virtual void AddRange(ICollection c)
Adds the elements of an T:System.Collections.ICollection to the end of the T:System....
Definition: ArrayList.cs:2397
override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
WebHeaderCollection()
Initializes a new instance of the T:System.Net.WebHeaderCollection class.
HttpRequestHeader
The HTTP headers that may be specified in a client request.
virtual string GetKey(int index)
Gets the key at the specified index of the T:System.Collections.Specialized.NameValueCollection.
virtual void Set(string name, string value)
Sets the value of an entry in the T:System.Collections.Specialized.NameValueCollection.
void Remove(HttpRequestHeader header)
Removes the specified header from the collection.
Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that can...
void Add(HttpResponseHeader header, string value)
Inserts the specified header with the specified value into the collection.
WebHeaderCollection(SerializationInfo serializationInfo, StreamingContext streamingContext)
Initializes a new instance of the T:System.Net.WebHeaderCollection class from the specified instances...
virtual KeysCollection Keys
Gets a T:System.Collections.Specialized.NameObjectCollectionBase.KeysCollection instance that contain...
virtual void CopyTo(Array array)
Copies the entire T:System.Collections.ArrayList to a compatible one-dimensional T:System....
Definition: ArrayList.cs:2516
override string Get(string name)
Gets the value of a particular header in the collection, specified by the name of the header.
virtual void RemoveRange(int index, int count)
Removes a range of elements from the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2871
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
The exception that is thrown when one of the arguments provided to a method is not valid.
void InvalidateCachedArrays()
Resets the cached arrays of the collection to null.
override void Remove(string name)
Removes the specified header from the collection.
override string [] GetValues(int index)
Gets an array of header values stored in the index position of the header collection.
byte [] ToByteArray()
Converts the T:System.Net.WebHeaderCollection to a byte array..
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
override string GetKey(int index)
Gets the header name at the specified position in the collection.
void Add(string header)
Inserts the specified header into the collection.
string GetString(string name)
Retrieves a T:System.String value from the T:System.Runtime.Serialization.SerializationInfo store.
void Set(HttpResponseHeader header, string value)
Sets the specified header to the specified value.
Specifies that the class can be serialized.
static bool IsRestricted(string headerName, bool response)
Tests whether the specified HTTP header can be set for the request or the response.
virtual int Count
Gets the number of key/value pairs contained in the T:System.Collections.Specialized....
The exception that is thrown when a method call is invalid for the object's current state.
int GetInt32(string name)
Retrieves a 32-bit signed integer value from the T:System.Runtime.Serialization.SerializationInfo sto...
static EncoderFallback ExceptionFallback
Gets an object that throws an exception when an input character cannot be encoded.
void Add(NameValueCollection c)
Copies the entries in the specified T:System.Collections.Specialized.NameValueCollection to the curre...
SecurityPermissionFlag
Specifies access flags for the security permission object.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
override KeysCollection Keys
Gets the collection of header names (keys) in the collection.
override void OnDeserialization(object sender)
Implements the T:System.Runtime.Serialization.ISerializable interface and raises the deserialization ...
void Remove(HttpResponseHeader header)
Removes the specified header from the collection.
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
override string [] AllKeys
Gets all header names (keys) in the collection.
HttpResponseHeader
The HTTP headers that can be specified in a server response.
static NumberFormatInfo InvariantInfo
Gets a read-only T:System.Globalization.NumberFormatInfo object that is culture-independent (invarian...
override void Set(string name, string value)
Sets the specified header to the specified value.
NameValueCollection()
Initializes a new instance of the T:System.Collections.Specialized.NameValueCollection class that is ...
Represents a nonexistent value. This class cannot be inherited.
Definition: DBNull.cs:10
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14
Provides culture-specific information for formatting and parsing numeric values.