Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        public void ParseRequestHeader(string data)
        {
            MatchCollection matches = Regex.Matches(data, @"([^\r\n]+)\r\n");

            if (matches == null)
            {
                if (data.Length > 50)
                {
                    throw new ArgumentException("Unable to parse HTTP header from data: [" + data.Substring(0, 50) + "]");
                }
                else
                {
                    throw new ArgumentException("Unable to parse HTTP header from data: [" + data + "]");
                }
            }

            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;
                }

                logger.Debug("ParseRequestHeader: Header: " + header.Name);
                Headers.Add(header.Name.ToLower(), header);
            }
        }