示例#1
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();
            if (requestLine.RequestUri.Length == 0)
            {
                return(false);
            }

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

            totalParsedBytes = buffer.Length - reader.Buffer.Length;
            return(true);
        }
示例#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();
            if(requestLine.RequestUri.Length == 0) { return false; }

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

            totalParsedBytes = buffer.Length - reader.Buffer.Length;
            return true;
        }
示例#3
0
文件: Log.cs 项目: GrimDerp/corefxlab
        public static void LogRequest(this Log log, HttpRequest request)
        {
            if (log.IsVerbose)
            {
                log.LogMessage(Log.Level.Verbose, "\tMethod:       {0}", request.RequestLine.Method);
                log.LogMessage(Log.Level.Verbose, "\tRequest-URI:  {0}", request.RequestLine.RequestUri.ToString());
                log.LogMessage(Log.Level.Verbose, "\tHTTP-Version: {0}", request.RequestLine.Version);

                log.LogMessage(Log.Level.Verbose, "\tHttp Headers:");
                foreach (var httpHeader in request.Headers)
                {
                    log.LogMessage(Log.Level.Verbose, "\t\tName: {0}, Value: {1}", httpHeader.Key, httpHeader.Value);
                }

                HttpRequestReader reader = new HttpRequestReader();
                reader.Buffer = request.Body;
                while (true)
                {
                    var header = reader.ReadHeader();
                    if (header.Length == 0) break;
                    log.LogMessage(Log.Level.Verbose, "\tHeader: {0}", header.ToString());
                }
                var messageBody = reader.Buffer;
                log.LogMessage(Log.Level.Verbose, "\tBody bytecount: {0}", messageBody.Length);
            }
        }