private static ParseInfo Parse(byte[] buffer, int offset, int length) { // First Line HttpParser parser = new HttpParser(buffer, offset, length); HttpVersion version; uint? statusCode; Datagram reasonPhrase; parser.Version(out version).Space().DecimalNumber(3, out statusCode).Space().SkipSpaces().ReasonPhrase(out reasonPhrase).CarriageReturnLineFeed(); ParseInfo parseInfo = new ParseInfo { Length = length, Version = version, StatusCode = statusCode, ReasonPhrase = reasonPhrase }; if (!parser.Success) return parseInfo; int firstLineLength = parser.Offset - offset; // Header int? endHeaderOffset; HttpHeader header = new HttpHeader(GetHeaderFields(out endHeaderOffset, buffer, offset + firstLineLength, length - firstLineLength)); parseInfo.Header = header; if (endHeaderOffset == null) return parseInfo; int headerLength = endHeaderOffset.Value - offset - firstLineLength; // Body Datagram body = ParseBody(buffer, offset + firstLineLength + headerLength, length - firstLineLength - headerLength, IsBodyPossible(statusCode.Value), header); parseInfo.Body = body; parseInfo.Length = firstLineLength + headerLength + body.Length; return parseInfo; }
private static HttpResponseDatagram.ParseInfo Parse(byte[] buffer, int offset, int length) { HttpParser httpParser = new HttpParser(buffer, offset, length); HttpVersion version; uint? number; Datagram reasonPhrase; httpParser.Version(out version).Space().DecimalNumber(3, out number).Space().SkipSpaces().ReasonPhrase(out reasonPhrase).CarriageReturnLineFeed(); HttpResponseDatagram.ParseInfo parseInfo1 = new HttpResponseDatagram.ParseInfo(); parseInfo1.Length = length; parseInfo1.Version = version; parseInfo1.StatusCode = number; parseInfo1.ReasonPhrase = reasonPhrase; HttpResponseDatagram.ParseInfo parseInfo2 = parseInfo1; if (!httpParser.Success) { return(parseInfo2); } int num1 = httpParser.Offset - offset; int? endOffset; HttpHeader header = new HttpHeader((IEnumerable <KeyValuePair <string, IEnumerable <byte> > >)HttpDatagram.GetHeaderFields(out endOffset, buffer, offset + num1, length - num1)); parseInfo2.Header = header; if (!endOffset.HasValue) { return(parseInfo2); } int num2 = endOffset.Value - offset - num1; Datagram datagram = HttpDatagram.ParseBody(buffer, offset + num1 + num2, length - num1 - num2, HttpResponseDatagram.IsBodyPossible(number.Value), header); parseInfo2.Body = datagram; parseInfo2.Length = num1 + num2 + datagram.Length; return(parseInfo2); }
private static ParseInfo Parse(byte[] buffer, int offset, int length) { // First Line HttpParser parser = new HttpParser(buffer, offset, length); HttpVersion version; uint? statusCode; Datagram reasonPhrase; parser.Version(out version).Space().DecimalNumber(3, out statusCode).Space().SkipSpaces().ReasonPhrase(out reasonPhrase).CarriageReturnLineFeed(); ParseInfo parseInfo = new ParseInfo { Length = length, Version = version, StatusCode = statusCode, ReasonPhrase = reasonPhrase }; if (!parser.Success) { return(parseInfo); } int firstLineLength = parser.Offset - offset; // Header int? endHeaderOffset; HttpHeader header = new HttpHeader(GetHeaderFields(out endHeaderOffset, buffer, offset + firstLineLength, length - firstLineLength)); parseInfo.Header = header; if (endHeaderOffset == null) { return(parseInfo); } int headerLength = endHeaderOffset.Value - offset - firstLineLength; // Body Datagram body = ParseBody(buffer, offset + firstLineLength + headerLength, length - firstLineLength - headerLength, IsBodyPossible(statusCode.Value), header); parseInfo.Body = body; parseInfo.Length = firstLineLength + headerLength + body.Length; return(parseInfo); }