Esempio n. 1
0
        public static Header ParseFromInput(Stream input, int timeout = int.MaxValue)
        {
            var header = new Header
            {
                HttpHeaders = new Hashtable()
            };

            do
            {
                var line = input.StringReadLine<UTF8Encoding>(timeout);
                if (string.IsNullOrWhiteSpace(line))
                {
                    break;
                }

                var splittedHeaderLine = line.Split(':');

                if (splittedHeaderLine.Length < 2)
                {
                    throw new Exception("Invalid HTTP header: " + line);
                }

                var name = splittedHeaderLine[0].ToLower();
                var value = string.Join(":", splittedHeaderLine.Skip(1));

                header.HttpHeaders[name] = value.Trim();
            }
            while (true);

            header.Accept = Accept.GetFromHeaders(header.HttpHeaders);

            return header;
        }