Exemplo n.º 1
0
        private IEnumerable <BytesWraper> ReceiveMessageBodyZip(int contentLength)
        {
            BytesWraper     bytesWraper   = new BytesWraper();
            ZipWraperStream streamWrapper = new ZipWraperStream(_request.ClientStream, _receiverHelper);

            using (Stream stream = GetZipStream(streamWrapper))
            {
                int    bufferSize = _request.TcpClient.ReceiveBufferSize;
                byte[] buffer     = bytesWraper.Value = new byte[bufferSize];
                while (true)
                {
                    int num = stream.Read(buffer, 0, bufferSize);
                    if (num == 0)
                    {
                        if (streamWrapper.TotalBytesRead == contentLength)
                        {
                            break;
                        }
                        WaitData();
                    }
                    else
                    {
                        bytesWraper.Length = num;
                        yield return(bytesWraper);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private IEnumerable <BytesWraper> ReceiveMessageBodyChunkedZip()
        {
            BytesWraper     bytesWraper   = new BytesWraper();
            ZipWraperStream streamWrapper = new ZipWraperStream(_request.ClientStream, _receiverHelper);

            using (Stream stream = GetZipStream(streamWrapper))
            {
                int    bufferSize = _request.TcpClient.ReceiveBufferSize;
                byte[] buffer     = bytesWraper.Value = new byte[bufferSize];
                while (true)
                {
                    string text = _receiverHelper.ReadLine();
                    if (!(text == "\r\n"))
                    {
                        text = text.Trim(' ', '\r', '\n');
                        if (text == string.Empty)
                        {
                            break;
                        }
                        int blockLength;
                        try
                        {
                            blockLength = Convert.ToInt32(text, 16);
                        }
                        catch (Exception ex)
                        {
                            if (ex is FormatException || ex is OverflowException)
                            {
                                throw NewHttpException(string.Format(Resources.HttpException_WrongChunkedBlockLength, text), ex);
                            }
                            throw;
                        }
                        if (blockLength == 0)
                        {
                            break;
                        }
                        streamWrapper.TotalBytesRead = 0;
                        streamWrapper.LimitBytesRead = blockLength;
                        while (true)
                        {
                            int num = stream.Read(buffer, 0, bufferSize);
                            if (num == 0)
                            {
                                if (streamWrapper.TotalBytesRead == blockLength)
                                {
                                    break;
                                }
                                WaitData();
                            }
                            else
                            {
                                bytesWraper.Length = num;
                                yield return(bytesWraper);
                            }
                        }
                    }
                }
            }
            /*Error near IL_01c5: Unexpected return in MoveNext()*/;
        }
Exemplo n.º 3
0
        private IEnumerable <BytesWraper> ReceiveMessageBodyZip(int contentLength)
        {
            var bytesWraper   = new BytesWraper();
            var streamWrapper = new ZipWraperStream(commonStream, receiveHelper);

            using (Stream stream = GetZipStream(streamWrapper))
            {
                byte[] buffer = new byte[bufferSize];
                bytesWraper.Value = buffer;

                while (true)
                {
                    int bytesRead = stream.Read(buffer, 0, bufferSize);
                    if (bytesRead == 0)
                    {
                        if (streamWrapper.TotalBytesRead == contentLength)
                        {
                            yield break;
                        }
                        else
                        {
                            WaitData();
                            continue;
                        }
                    }
                    bytesWraper.Length = bytesRead;
                    yield return(bytesWraper);
                }
            }
        }
Exemplo n.º 4
0
        private IEnumerable <BytesWraper> GetMessageBodySourceZip()
        {
            if (_headers.ContainsKey("Transfer-Encoding"))
            {
                return(ReceiveMessageBodyChunkedZip());
            }
            if (ContentLength != -1)
            {
                return(ReceiveMessageBodyZip(ContentLength));
            }
            ZipWraperStream stream = new ZipWraperStream(_request.ClientStream, _receiverHelper);

            return(ReceiveMessageBody(GetZipStream(stream)));
        }
Exemplo n.º 5
0
        // Загрузка сжатых данных.
        private IEnumerable <BytesWraper> GetMessageBodySourceZip()
        {
            if (response.Headers.Contains("Transfer-Encoding"))
            {
                return(ReceiveMessageBodyChunkedZip());
            }

            if (contentLength != -1)
            {
                return(ReceiveMessageBodyZip(contentLength));
            }

            var streamWrapper = new ZipWraperStream(commonStream, receiveHelper);

            return(ReceiveMessageBody(GetZipStream(streamWrapper)));
        }
Exemplo n.º 6
0
        private IEnumerable<BytesWraper> ReceiveMessageBodyChunkedZip()
        {
            var bytesWraper = new BytesWraper();
            var streamWrapper = new ZipWraperStream
                (_request.ClientStream, _receiverHelper);

            using (Stream stream = GetZipStream(streamWrapper))
            {
                int bufferSize = _request.TcpClient.ReceiveBufferSize;
                byte[] buffer = new byte[bufferSize];

                bytesWraper.Value = buffer;

                while (true)
                {
                    string line = _receiverHelper.ReadLine();

                    // Если достигнут конец блока.
                    if (line.Equals(
                        HttpHelper.NewLine, StringComparison.Ordinal))
                    {
                        continue;
                    }

                    line = line.Trim(' ', '\r', '\n');

                    // Если достигнут конец данных.
                    if (line.Equals("0", StringComparison.Ordinal))
                    {
                        yield break;
                    }

                    int blockLength;

                    #region Задаём длину блока

                    try
                    {
                        blockLength = Convert.ToInt32(line, 16);
                    }
                    catch (Exception ex)
                    {
                        if (ex is FormatException || ex is OverflowException)
                        {
                            throw NewHttpException(string.Format(
                                Resources.HttpException_WrongChunkedBlockLength, line), ex);
                        }

                        throw;
                    }

                    #endregion

                    streamWrapper.TotalBytesRead = 0;
                    streamWrapper.LimitBytesRead = blockLength;

                    while (true)
                    {
                        int bytesRead = stream.Read(buffer, 0, bufferSize);

                        if (bytesRead == 0)
                        {
                            if (streamWrapper.TotalBytesRead == blockLength)
                            {
                                break;
                            }
                            else
                            {
                                WaitData();

                                continue;
                            }
                        }

                        bytesWraper.Length = bytesRead;
                        yield return bytesWraper;
                    }
                }
            }
        }
Exemplo n.º 7
0
        private IEnumerable<BytesWraper> ReceiveMessageBodyZip(int contentLength)
        {
            var bytesWraper = new BytesWraper();
            var streamWrapper = new ZipWraperStream(
                _request.ClientStream, _receiverHelper);

            using (Stream stream = GetZipStream(streamWrapper))
            {
                int bufferSize = _request.TcpClient.ReceiveBufferSize;
                byte[] buffer = new byte[bufferSize];

                bytesWraper.Value = buffer;

                while (true)
                {
                    int bytesRead = stream.Read(buffer, 0, bufferSize);

                    if (bytesRead == 0)
                    {
                        if (streamWrapper.TotalBytesRead == contentLength)
                        {
                            yield break;
                        }
                        else
                        {
                            WaitData();

                            continue;
                        }
                    }

                    bytesWraper.Length = bytesRead;
                    yield return bytesWraper;
                }
            }
        }
Exemplo n.º 8
0
        // Загрузка сжатых данных.
        private IEnumerable<BytesWraper> GetMessageBodySourceZip()
        {
            if (_headers.ContainsKey("Transfer-Encoding"))
            {
                return ReceiveMessageBodyChunkedZip();
            }

            if (ContentLength != -1)
            {
                return ReceiveMessageBodyZip(ContentLength);
            }

            var streamWrapper = new ZipWraperStream(
                _request.ClientStream, _receiverHelper);

            return ReceiveMessageBody(GetZipStream(streamWrapper));
        }
Exemplo n.º 9
0
        private IEnumerable <BytesWraper> ReceiveMessageBodyChunkedZip()
        {
            var bytesWraper   = new BytesWraper();
            var streamWrapper = new ZipWraperStream(commonStream, receiveHelper);

            using (Stream stream = GetZipStream(streamWrapper))
            {
                byte[] buffer = new byte[bufferSize];
                bytesWraper.Value = buffer;
                while (true)
                {
                    string line = receiveHelper.ReadLine();
                    // Если достигнут конец блока.
                    if (line == newLine)
                    {
                        continue;
                    }

                    line = line.Trim(' ', '\r', '\n');
                    // Если достигнут конец тела сообщения.
                    if (line == string.Empty)
                    {
                        yield break;
                    }

                    int blockLength;
                    #region Задаём длину блока
                    try
                    {
                        blockLength = Convert.ToInt32(line, 16);
                    }
                    catch (Exception ex)
                    {
                        if (ex is FormatException || ex is OverflowException)
                        {
                            //throw NewHttpException(string.Format(
                            //Resources.HttpException_WrongChunkedBlockLength, line), ex);
                        }
                        throw;
                    }
                    #endregion
                    // Если достигнут конец тела сообщения.
                    if (blockLength == 0)
                    {
                        yield break;
                    }

                    streamWrapper.TotalBytesRead = 0;
                    streamWrapper.LimitBytesRead = blockLength;
                    while (true)
                    {
                        int bytesRead = stream.Read(buffer, 0, bufferSize);
                        if (bytesRead == 0)
                        {
                            if (streamWrapper.TotalBytesRead == blockLength)
                            {
                                break;
                            }
                            else
                            {
                                WaitData();
                                continue;
                            }
                        }
                        bytesWraper.Length = bytesRead;
                        yield return(bytesWraper);
                    }
                }
            }
        }