示例#1
0
        public static HttpRequest Parse(ReadOnlySpan <byte> bytes)
        {
            int             parsed;
            HttpRequestLine requestLine;

            if (!HttpRequestParser.TryParseRequestLine(bytes, out requestLine, out parsed))
            {
                throw new NotImplementedException("request line parser");
            }
            bytes = bytes.Slice(parsed);

            HttpHeaders headers;

            if (!HttpRequestParser.TryParseHeaders(bytes, out headers, out parsed))
            {
                throw new NotImplementedException("headers parser");
            }
            var body = bytes.Slice(parsed);

            var request = new HttpRequest(requestLine, headers, body);

            return(request);
        }
        public static HttpRequest Parse(Span <byte> bytes)
        {
            int             parsed;
            HttpRequestLine requestLine;

            if (!HttpRequestParser.TryParseRequestLine(bytes, out requestLine, out parsed))
            {
                throw new NotImplementedException();
            }
            bytes = bytes.Slice(parsed);

            HttpHeaders headers;

            if (!HttpRequestParser.TryParseHeaders(bytes, out headers, out parsed))
            {
                throw new NotImplementedException();
            }
            var body = bytes.Slice(parsed + 4); // TODO: this needs to verify two newlines

            var request = new HttpRequest(requestLine, headers, body);

            return(request);
        }