Example #1
0
        private static HttpRequestDatagram.ParseInfo Parse(byte[] buffer, int offset, int length)
        {
            HttpParser  httpParser = new HttpParser(buffer, offset, length);
            string      token;
            string      uri;
            HttpVersion version;

            httpParser.Token(out token).Space().RequestUri(out uri).Space().Version(out version).CarriageReturnLineFeed();
            HttpRequestDatagram.ParseInfo parseInfo1 = new HttpRequestDatagram.ParseInfo();
            parseInfo1.Length  = length;
            parseInfo1.Version = version;
            parseInfo1.Method  = token == null ? (HttpRequestMethod)null : new HttpRequestMethod(token);
            parseInfo1.Uri     = uri;
            HttpRequestDatagram.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, HttpRequestDatagram.IsBodyPossible(header), header);

            parseInfo2.Body   = datagram;
            parseInfo2.Length = num1 + num2 + datagram.Length;
            return(parseInfo2);
        }
Example #2
0
 private HttpRequestDatagram(byte[] buffer, int offset, HttpRequestDatagram.ParseInfo parseInfo)
     : base(buffer, offset, parseInfo.Length, parseInfo.Version, parseInfo.Header, parseInfo.Body)
 {
     this.Method = parseInfo.Method;
     this.Uri    = parseInfo.Uri;
 }