Пример #1
0
        public void ParseRequestHeader(string data)
        {
            MatchCollection matches = Regex.Matches(data, @"([^\r\n]+)\r\n");

            if (matches == null)
            {
                throw new ArgumentException("Unable to parse data into HTTP Request Line");
            }

            Headers = new HttpHeaderCollection();
            foreach (Match match in matches)
            {
                if (match.Groups.Count < 2)
                {
                    break;
                }

                var header = HttpHeader.Parse(match.Groups[1].Value);
                if (header == null)
                {
                    break;
                }

                string headerName = header.Name.ToLower();
                int    cnt        = 0;
                while (Headers.ContainsKey(headerName))
                {
                    headerName += ++cnt;
                }

                Headers.Add(headerName, header);
            }
        }