Пример #1
0
        private static Datagram ParseChunkedBody(byte[] buffer, int offset, int length)
        {
            List <Datagram> list       = new List <Datagram>();
            HttpParser      httpParser = new HttpParser(buffer, offset, length);
            uint?           number;

            while (httpParser.HexadecimalNumber(out number).SkipChunkExtensions().CarriageReturnLineFeed().Success)
            {
                uint num1 = number.Value;
                if ((int)num1 == 0)
                {
                    int?endOffset;
                    HttpDatagram.GetHeaderFields(out endOffset, buffer, httpParser.Offset, offset + length - httpParser.Offset);
                    if (endOffset.HasValue)
                    {
                        httpParser.Skip(endOffset.Value - httpParser.Offset);
                        break;
                    }
                    break;
                }
                int num2 = (int)Math.Min((long)num1, (long)(offset + length - httpParser.Offset));
                list.Add(new Datagram(buffer, httpParser.Offset, num2));
                httpParser.Skip(num2);
                httpParser.CarriageReturnLineFeed();
            }
            byte[] buffer1 = new byte[Enumerable.Sum <Datagram>((IEnumerable <Datagram>)list, (Func <Datagram, int>)(datagram => datagram.Length))];
            int    offset1 = 0;

            foreach (Datagram datagram in list)
            {
                datagram.Write(buffer1, offset1);
                offset1 += datagram.Length;
            }
            return(new Datagram(buffer, offset, httpParser.Offset - offset));
        }
Пример #2
0
        private static Datagram ParseChunkedBody(byte[] buffer, int offset, int length)
        {
            List <Datagram> contentData = new List <Datagram>();
            HttpParser      parser      = new HttpParser(buffer, offset, length);
            uint?           chunkSize;

            while (parser.HexadecimalNumber(out chunkSize).SkipChunkExtensions().CarriageReturnLineFeed().Success)
            {
                uint chunkSizeValue = chunkSize.Value;
                if (chunkSizeValue == 0)
                {
                    int?endOffset;
//                    HttpHeader trailerHeader = new HttpHeader(
                    GetHeaderFields(out endOffset, buffer, parser.Offset, offset + length - parser.Offset)
//                        )
                    ;
                    if (endOffset != null)
                    {
                        parser.Skip(endOffset.Value - parser.Offset);
                    }
                    break;
                }

                int actualChunkSize = (int)Math.Min(chunkSizeValue, offset + length - parser.Offset);
                contentData.Add(new Datagram(buffer, parser.Offset, actualChunkSize));
                parser.Skip(actualChunkSize);
                parser.CarriageReturnLineFeed();
            }

            int contentLength = contentData.Sum(datagram => datagram.Length);

            byte[] contentBuffer       = new byte[contentLength];
            int    contentBufferOffset = 0;

            foreach (Datagram datagram in contentData)
            {
                datagram.Write(contentBuffer, contentBufferOffset);
                contentBufferOffset += datagram.Length;
            }
//            Datagram content = new Datagram(contentBuffer);

            return(new Datagram(buffer, offset, parser.Offset - offset));
        }
Пример #3
0
        private static Datagram ParseChunkedBody(byte[] buffer, int offset, int length)
        {
            List<Datagram> contentData = new List<Datagram>();
            HttpParser parser = new HttpParser(buffer, offset, length);
            uint? chunkSize;
            while (parser.HexadecimalNumber(out chunkSize).SkipChunkExtensions().CarriageReturnLineFeed().Success)
            {
                uint chunkSizeValue = chunkSize.Value;
                if (chunkSizeValue == 0)
                {
                    int? endOffset;
            //                    HttpHeader trailerHeader = new HttpHeader(
                        GetHeaderFields(out endOffset, buffer, parser.Offset, offset + length - parser.Offset)
            //                        )
                        ;
                    if (endOffset != null)
                        parser.Skip(endOffset.Value - parser.Offset);
                    break;
                }

                int actualChunkSize = (int)Math.Min(chunkSizeValue, offset + length - parser.Offset);
                contentData.Add(new Datagram(buffer, parser.Offset, actualChunkSize));
                parser.Skip(actualChunkSize);
                parser.CarriageReturnLineFeed();
            }

            int contentLength = contentData.Sum(datagram => datagram.Length);
            byte[] contentBuffer = new byte[contentLength];
            int contentBufferOffset = 0;
            foreach (Datagram datagram in contentData)
            {
                datagram.Write(contentBuffer, contentBufferOffset);
                contentBufferOffset += datagram.Length;
            }
            //            Datagram content = new Datagram(contentBuffer);

            return new Datagram(buffer, offset, parser.Offset - offset);
        }