Exemple #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);
             }
         }
     }
 }
Exemple #2
0
        private IEnumerable <HttpResponse.BytesWraper> ReceiveMessageBody(
            int contentLength)
        {
            Stream stream = this._request.ClientStream;

            HttpResponse.BytesWraper bytesWraper = new HttpResponse.BytesWraper();
            int bufferSize = this._request.TcpClient.ReceiveBufferSize;

            byte[] buffer = new byte[bufferSize];
            bytesWraper.Value = buffer;
            int totalBytesRead = 0;

            while (totalBytesRead != contentLength)
            {
                int num = !this._receiverHelper.HasData ? stream.Read(buffer, 0, bufferSize) : this._receiverHelper.Read(buffer, 0, bufferSize);
                if (num == 0)
                {
                    this.WaitData();
                }
                else
                {
                    totalBytesRead    += num;
                    bytesWraper.Length = num;
                    yield return(bytesWraper);
                }
            }
        }
Exemple #3
0
        private IEnumerable <HttpResponse.BytesWraper> ReceiveMessageBodyChunked()
        {
            Stream stream = this._request.ClientStream;

            HttpResponse.BytesWraper bytesWraper = new HttpResponse.BytesWraper();
            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))
            {
                int totalBytesRead = 0;
                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)
                {
                    while (totalBytesRead != blockLength)
                    {
                        int num1 = blockLength - totalBytesRead;
                        if (num1 > bufferSize)
                        {
                            num1 = bufferSize;
                        }
                        int num2 = !this._receiverHelper.HasData ? stream.Read(buffer, 0, num1) : this._receiverHelper.Read(buffer, 0, num1);
                        if (num2 == 0)
                        {
                            this.WaitData();
                        }
                        else
                        {
                            totalBytesRead    += num2;
                            bytesWraper.Length = num2;
                            yield return(bytesWraper);
                        }
                    }
                    goto label_1;
                }
            }
        }
Exemple #4
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);
        }
Exemple #5
0
        private IEnumerable <HttpResponse.BytesWraper> ReceiveMessageBody(
            Stream stream)
        {
            HttpResponse.BytesWraper bytesWraper = new HttpResponse.BytesWraper();
            int bufferSize = this._request.TcpClient.ReceiveBufferSize;

            byte[] buffer = new byte[bufferSize];
            bytesWraper.Value = buffer;
            int begBytesRead = 0;

            if (stream is GZipStream || stream is DeflateStream)
            {
                begBytesRead = stream.Read(buffer, 0, bufferSize);
            }
            else
            {
                if (this._receiverHelper.HasData)
                {
                    begBytesRead = this._receiverHelper.Read(buffer, 0, bufferSize);
                }
                if (begBytesRead < bufferSize)
                {
                    begBytesRead += stream.Read(buffer, begBytesRead, bufferSize - begBytesRead);
                }
            }
            bytesWraper.Length = begBytesRead;
            yield return(bytesWraper);

            bool isHtml = this.FindSignature(buffer, begBytesRead, HttpResponse._openHtmlSignature);

            if (!isHtml || !this.FindSignature(buffer, begBytesRead, HttpResponse._closeHtmlSignature))
            {
                int sourceLength;
                while (true)
                {
                    sourceLength = stream.Read(buffer, 0, bufferSize);
                    if (isHtml)
                    {
                        if (sourceLength == 0)
                        {
                            this.WaitData();
                            continue;
                        }
                        if (this.FindSignature(buffer, sourceLength, HttpResponse._closeHtmlSignature))
                        {
                            break;
                        }
                    }
                    else if (sourceLength == 0)
                    {
                        goto label_8;
                    }
                    bytesWraper.Length = sourceLength;
                    yield return(bytesWraper);
                }
                bytesWraper.Length = sourceLength;
                yield return(bytesWraper);

                yield break;
                label_8 :;
            }
        }