示例#1
0
        internal static int TryParseRequestLine(ReadOnlySpan <byte> buffer, out HttpRequestLine requestLine)
        {
            requestLine = new HttpRequestLine();

            var reader = new HttpRequestReader();

            reader.Buffer = buffer;

            requestLine.Method = reader.ReadMethod();
            if (requestLine.Method == HttpMethod.Unknown)
            {
                return(0);
            }

            requestLine.RequestUri = reader.ReadRequestUri().Bytes.ToArray();
            if (requestLine.RequestUri.Length == 0)
            {
                return(0);
            }
            reader.Buffer = reader.Buffer.Slice(1);

            requestLine.Version = reader.ReadHttpVersion();
            if (requestLine.Version == HttpVersion.Unknown)
            {
                return(0);
            }

            return(buffer.Length - reader.Buffer.Length);
        }
示例#2
0
        internal static bool TryParseRequestLine(ReadOnlySpan <byte> buffer, out HttpRequestLine requestLine, out int totalParsedBytes)
        {
            requestLine      = new HttpRequestLine();
            totalParsedBytes = 0;

            var reader = new HttpRequestReader();

            reader.Buffer = buffer;

            requestLine.Method = reader.ReadMethod();
            if (requestLine.Method == HttpMethod.Unknown)
            {
                return(false);
            }

            requestLine.RequestUri = reader.ReadRequestUri().Bytes.ToArray();
            if (requestLine.RequestUri.Length == 0)
            {
                return(false);
            }
            reader.Buffer = reader.Buffer.Slice(1);

            requestLine.Version = reader.ReadHttpVersion();
            if (requestLine.Version == HttpVersion.Unknown)
            {
                return(false);
            }

            totalParsedBytes = buffer.Length - reader.Buffer.Length;
            return(true);
        }