Пример #1
0
 private IEnumerable <HttpResponse.BytesWraper> ReceiveMessageBodyZip(
     int contentLength)
 {
     HttpResponse.BytesWraper     bytesWraper   = new HttpResponse.BytesWraper();
     HttpResponse.ZipWraperStream streamWrapper = new HttpResponse.ZipWraperStream(this._request.ClientStream, this._receiverHelper);
     using (Stream stream = this.GetZipStream((Stream)streamWrapper))
     {
         int    bufferSize = this._request.TcpClient.ReceiveBufferSize;
         byte[] buffer     = new byte[bufferSize];
         bytesWraper.Value = buffer;
         while (true)
         {
             int num = stream.Read(buffer, 0, bufferSize);
             if (num == 0)
             {
                 if (streamWrapper.TotalBytesRead != contentLength)
                 {
                     this.WaitData();
                 }
                 else
                 {
                     break;
                 }
             }
             else
             {
                 bytesWraper.Length = num;
                 yield return(bytesWraper);
             }
         }
     }
 }
Пример #2
0
        private IEnumerable <HttpResponse.BytesWraper> ReceiveMessageBodyChunkedZip()
        {
            HttpResponse.BytesWraper     bytesWraper   = new HttpResponse.BytesWraper();
            HttpResponse.ZipWraperStream streamWrapper = new HttpResponse.ZipWraperStream(this._request.ClientStream, this._receiverHelper);
            bool flag;

            using (Stream stream = this.GetZipStream((Stream)streamWrapper))
            {
                int    bufferSize = this._request.TcpClient.ReceiveBufferSize;
                byte[] buffer     = new byte[bufferSize];
                bytesWraper.Value = buffer;
label_1:
                string str1;
                do
                {
                    str1 = this._receiverHelper.ReadLine();
                }while (str1 == "\r\n");
                string str2 = str1.Trim(' ', '\r', '\n');
                if (str2 == string.Empty)
                {
                    flag = false;
                }
                else
                {
                    int blockLength;
                    try
                    {
                        blockLength = Convert.ToInt32(str2, 16);
                    }
                    catch (Exception ex)
                    {
                        if (ex is FormatException || ex is OverflowException)
                        {
                            throw this.NewHttpException(string.Format(Resources.HttpException_WrongChunkedBlockLength, (object)str2), ex);
                        }
                        throw;
                    }
                    if (blockLength == 0)
                    {
                        flag = false;
                    }
                    else
                    {
                        streamWrapper.TotalBytesRead = 0;
                        streamWrapper.LimitBytesRead = blockLength;
                        while (true)
                        {
                            int num = stream.Read(buffer, 0, bufferSize);
                            if (num == 0)
                            {
                                if (streamWrapper.TotalBytesRead != blockLength)
                                {
                                    this.WaitData();
                                }
                                else
                                {
                                    goto label_1;
                                }
                            }
                            else
                            {
                                bytesWraper.Length = num;
                                yield return(bytesWraper);
                            }
                        }
                    }
                }
            }
            return(flag);
        }