Ejemplo n.º 1
0
        internal static Datagram ParseBody(byte[] buffer, int offset, int length, bool isBodyPossible, HttpHeader header)
        {
            if (!isBodyPossible)
            {
                return(Datagram.Empty);
            }
            HttpTransferEncodingField transferEncoding = header.TransferEncoding;

            if (transferEncoding != null && transferEncoding.TransferCodings != null && Enumerable.Any <string>((IEnumerable <string>)transferEncoding.TransferCodings, (Func <string, bool>)(coding => coding != "identity")))
            {
                return(HttpDatagram.ParseChunkedBody(buffer, offset, length));
            }
            HttpContentLengthField contentLength1 = header.ContentLength;

            if (contentLength1 != null)
            {
                uint?contentLength2 = contentLength1.ContentLength;
                if (contentLength2.HasValue)
                {
                    return(new Datagram(buffer, offset, Math.Min((int)contentLength2.Value, length)));
                }
            }
            HttpContentTypeField contentType = header.ContentType;

            if (contentType != null && contentType.MediaType == "multipart" && contentType.MediaSubtype == "byteranges")
            {
                string str = contentType.Parameters["boundary"];
                if (str != null)
                {
                    byte[] bytes = Encoding.ASCII.GetBytes(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "\r\n--{0}--", new object[1]
                    {
                        (object)str
                    }));
                    int num = ByteArrayExtensions.Find(buffer, offset, length, bytes) + bytes.Length;
                    return(new Datagram(buffer, offset, Math.Min(num - offset, length)));
                }
            }
            return(new Datagram(buffer, offset, length));
        }
Ejemplo n.º 2
0
 private static bool IsBodyPossible(HttpHeader header)
 {
     return(header.ContentLength != null);
 }
Ejemplo n.º 3
0
 internal HttpDatagram(byte[] buffer, int offset, int length, HttpVersion version, HttpHeader header, Datagram body)
     : base(buffer, offset, length)
 {
     this.Version = version;
     this.Header  = header;
     this.Body    = body;
 }