/// <summary>
        /// Override to change the OnRead behavior
        /// </summary>
        /// <param name="ar"></param>
        protected virtual void OnRead(IAsyncResult ar)
        {
            try
            {
                if (_stop || Closed)
                {
                    return;
                }

                _isBusy = true;
                HttpProxyClientStreamWrapper wrapper = (HttpProxyClientStreamWrapper)ar.AsyncState;
                int bytesRead = 0;

                bytesRead = wrapper.EndRead(ar);

                //we are still connected and we read more bytes

                if (bytesRead > 0)
                {
                    // Append data to the request
                    _requestBuilder.AddChunkReference(Buffer, bytesRead);

                    _requestInfo = new HttpRequestInfo(_requestBuilder.ToArray(), false);

                    if (!_requestInfo.IsFullRequest)
                    {
                        // not finished keep on reading!
                        wrapper.BeginRead(Buffer, 0, Buffer.Length, new AsyncCallback(OnRead), wrapper);
                    }
                    else
                    {
                        lock (_proxyLock)
                        {
                            // Done reading, process the request
                            ProcessRequest();
                        }
                    }
                }
                else
                {
                    //we read 0 bytes
                    _isBusy = _requestBuilder.Length > 0;
                }
            }
            catch (Exception ex)
            {
                ClientStreamWrapper.Close();
                HttpServerConsole.Instance.WriteLine(ex);
            }
        }
Пример #2
0
 /// <summary>
 /// Creates a connection
 /// </summary>
 /// <param name="client">TCP client to use</param>
 /// <param name="isSecure">Whether to use SSL or not</param>
 /// <param name="dataStore">Data store to save requests/responses to or to read from</param>
 /// <param name="requestDescription">Description added to the data store</param>
 public BaseProxyConnection(TcpClient client, bool isSecure, ITrafficDataAccessor dataStore, string requestDescription)
 {
     _client = client;
     _clientStreamWrapper = new HttpProxyClientStreamWrapper(_client);
     _isSecure            = isSecure;
     _trafficDataStore    = dataStore;
     _requestDescription  = requestDescription;
     _requestBuilder      = new ByteArrayBuilder();
     if (dataStore != null)
     {
         _exclusions = dataStore.Profile.GetExclusions();
     }
     HttpServerConsole.Instance.WriteLine(LogMessageType.Information,
                                          "Inbound connection from {0}", ((IPEndPoint)client.Client.RemoteEndPoint).Address);
 }