/// <summary>
        /// Parses the first line in a request/response.
        /// </summary>
        /// <returns><c>true</c> if first line is well formatted; otherwise <c>false</c>.</returns>
        private bool ParseFirstLine()
        {
            _reader.Consume('\r', '\n');

            // Do not contain a complete first line.
            if (!_reader.Contains('\n'))
            {
                return(false);
            }

            var words = new string[3];

            words[0] = _reader.ReadUntil(' ');
            _reader.Consume(); // eat delimiter
            words[1] = _reader.ReadUntil(' ');
            _reader.Consume(); // eat delimiter
            words[2] = _reader.ReadLine();
            if (string.IsNullOrEmpty(words[0]) || string.IsNullOrEmpty(words[1]) || string.IsNullOrEmpty(words[2]))
            {
                throw new HttpException(HttpStatusCode.BadRequest, "Invalid request line: " + string.Join(" ", words));
            }

            OnFirstLine(words);
            _parserMethod = GetHeaderName;
            return(true);
        }
Exemple #2
0
        public void TestContains()
        {
            var buffer = Encoding.ASCII.GetBytes("Hello  \tworld.!");
            var slice  = new BufferSlice(buffer, 0, buffer.Length, buffer.Length);
            var reader = new BufferSliceReader(slice);

            reader.Contains(' ');
            Assert.Equal('H', reader.Current);
            Assert.Equal('e', reader.Peek);
        }