예제 #1
0
        protected async Task <Dictionary <string, string> > ReadAllHeaders()
        {
            var    headers = new Dictionary <string, string>();
            string line;

            while ((line = await HttpLineReader.ReadLineAsync(RawStream)) != null)
            {
                Match headerMatch;
                if (String.IsNullOrEmpty(line))
                {
                    break;
                }
                else if ((headerMatch = HeaderPattern.Match(line)).Success)
                {
                    // header names are always converted to lower case
                    var headerName  = headerMatch.Groups["Name"].Value.ToLower();
                    var headerValue = headerMatch.Groups["Value"].Value;
                    headers[headerName] = headerValue;
                }
            }

            return(headers);
        }
예제 #2
0
        protected async Task <HttpMessage> ReadGreeting()
        {
            var greeting = await HttpLineReader.ReadLineAsync(RawStream);

            if (greeting == null)
            {
                return(null);
            }

            Match greetingMatch;

            if ((greetingMatch = RequestGreetingPattern.Match(greeting)).Success)
            {
                var method = greetingMatch.Groups["Method"].Value;
                var query  = greetingMatch.Groups["Query"].Value;
                return(new HttpRequest
                {
                    Connection = Connection,
                    Method = method,
                    Query = query,
                });
            }
            else if ((greetingMatch = ResponseGreetingPattern.Match(greeting)).Success)
            {
                var statusCode = greetingMatch.Groups["StatusCode"].Value;
                return(new HttpResponse
                {
                    Connection = Connection,
                    StatusCode = statusCode,
                });
            }
            else
            {
                throw new InvalidDataException("HTTP greeting not understood.");
            }
        }