示例#1
0
 public HttpReadState(HttpWebRequest request)
 {
     WebRequest = request;
     WebResponse = null; 
     Stream = null;
     Buffer = new ArraySegment<byte>();
     StringDecoder = new StringDecoder();
     HasStillMoreBytesToRead = true;
 }
        private void ResetForNewResponse()
        {
            if (_errorDecoder != null)
            {
            	_errorDecoder.Dispose();
                _errorDecoder = null;
            }

            _readState = new ReadState();
            _currentReadState = ReadResponseHeader;
        }
示例#3
0
        public override void Parse(
            ResponseStatus responseStatus,
            ArraySegment<byte> bodyData,
            ArraySegment<byte> extras,
            ArraySegment<byte> key,
            int bytesOfBodyPreviouslyRead,
            int totalBodyLength)
        {
            if (bytesOfBodyPreviouslyRead == 0)
            {
                _decoder = new StringDecoder();
            }

            _decoder.Decode(bodyData);
        }
        private void ReadError()
        {
            int bytesToCopy = BufferUtils.CalculateMaxPossibleBytesForCopy(_currentByteInReceiveBuffer, _bytesAvailableFromLastRead, _readState.CurrentByteOfValue, _readState.ValueLength);
            
            if (_readState.CurrentByteOfValue == 0)
            {
            	_errorDecoder = new StringDecoder();
            }

            _errorDecoder.Decode(new ArraySegment<byte>(_receiveBuffer, _currentByteInReceiveBuffer, bytesToCopy));

            _currentByteInReceiveBuffer += bytesToCopy;
            _readState.CurrentByteOfValue += bytesToCopy;

            if (_readState.CurrentByteOfValue >= _readState.ValueLength)
            {
                _readState.Command.ErrorMessage = _errorDecoder.ToString();
                _onError(_readState.Command);
                ResetForNewResponse();
            }
        }