Exemple #1
0
        public static HttpRequest Parse(ReadOnlyBytes bytes)
        {
            var request = new HttpRequest();

            request.Bytes = bytes;

            var   reader = new BytesReader(bytes);
            Range?verb   = reader.ReadRangeUntil((byte)' ');

            request._verb = verb.Value;
            reader.Advance(1);

            Range?path = reader.ReadRangeUntil((byte)' ');

            request._path = path.Value;
            reader.Advance(1);

            Range?version = reader.ReadRangeUntil(Cr);

            request._version = version.Value;
            reader.Advance(2);

            var headers = reader.ReadRangeUntil(Cr2).Value;

            request._headers = new HttpHeaders()
            {
                _headers = bytes.Slice(headers.Index, headers.Length + 2)
            };

            request._bodyIndex = headers.Index + headers.Length + 4;
            return(request);
        }
    static void BytesReaderBasic()
    {
        var eol = new ReadOnlySpan <byte>(s_eol);

        foreach (var iteration in Benchmark.Iterations)
        {
            var reader = new BytesReader(s_bytes, SymbolTable.InvariantUtf8);

            using (iteration.StartMeasurement())
            {
                while (true)
                {
                    var result = reader.ReadRangeUntil(eol);
                    if (result == null)
                    {
                        break;
                    }
                    reader.Advance(eol.Length);
                }
            }
        }
    }