示例#1
0
        public void AddInSteps()
        {
            var slize = CreateSlice(@"GET / HTTP/1.1
Connection: Keep-Alive
HOST: localhost
Content-Length: 0

");

            slize.Count = 1;
            HttpParser parser = new HttpParser();

            Assert.Null(parser.Parse(slize));
            Assert.Equal(0, slize.Position);

            slize.Count = 10;
            Assert.Null(parser.Parse(slize));
            Assert.Equal(0, slize.Position);

            //first line
            slize.Count = 16;
            Assert.Null(parser.Parse(slize));
            Assert.Equal(16, slize.Position);

            slize.Count = 78 - 16;
            var request = parser.Parse(slize);

            Assert.Equal("Keep-Alive", request.Headers["Connection"].Value);
            Assert.Equal("localhost", request.Headers["HOST"].Value);
            Assert.Equal("0", request.Headers["Content-Length"].Value);
        }
示例#2
0
        public async Task ParserCanParseSampleMarkup()
        {
            //arrange
            HttpParser          parser = new HttpParser();
            IEnumerable <Match> result = await parser.Parse(File.ReadAllText("Integration//SampleMarkup.html"));

            //act
            result.ToList().ForEach(r => Console.WriteLine(r.Value));

            //assert
            // yeah yeah could assert a known match collection length.
        }
示例#3
0
        public void BasicDoc()
        {
            var        slize   = CreateSlice(@"GET / HTTP/1.1
Connection: Keep-Alive
HOST: localhost
Content-Length: 0

");
            HttpParser parser  = new HttpParser();
            var        request = parser.Parse(slize);

            Assert.Equal("Keep-Alive", request.Headers["Connection"].Value);
            Assert.Equal("localhost", request.Headers["HOST"].Value);
            Assert.Equal("0", request.Headers["Content-Length"].Value);
        }
示例#4
0
 /// <summary>
 /// Will continue the parsing until nothing more can be parsed.
 /// </summary>
 /// <param name="buffer">buffer to parse</param>
 /// <param name="offset">where to start in the buffer</param>
 /// <param name="length">number of bytes to process.</param>
 /// <returns>Position where parser stopped parsing.</returns>
 /// <exception cref="ParserException">Parsing failed.</exception>
 public int Parse(byte[] buffer, int offset, int length)
 {
     return(_parser.Parse(buffer, offset, length));
 }