private static void HandleConnectionStateChange(ConnectionEventInfo @event)
        {
            var connection = @event.Source;

            switch (@event.State)
            {
            case HTTPConnectionStates.Recycle:
                HostManager.GetHost(connection.LastProcessedUri.Host)
                .GetHostDefinition(connection.ServerAddress)
                .RecycleConnection(connection)
                .TryToSendQueuedRequests();

                break;

            case HTTPConnectionStates.WaitForProtocolShutdown:
                HostManager.GetHost(connection.LastProcessedUri.Host)
                .GetHostDefinition(connection.ServerAddress)
                .RemoveConnection(connection, @event.State);
                break;

            case HTTPConnectionStates.Closed:
            case HTTPConnectionStates.ClosedResendRequest:
                // in case of ClosedResendRequest
                if (@event.Request != null)
                {
                    RequestEventHelper.EnqueueRequestEvent(new RequestEventInfo(@event.Request, RequestEvents.Resend));
                }

                HostManager.GetHost(connection.LastProcessedUri.Host)
                .GetHostDefinition(connection.ServerAddress)
                .RemoveConnection(connection, @event.State)
                .TryToSendQueuedRequests();
                break;
            }
        }
        private static void HandleConnectionStateChange(ConnectionEventInfo @event)
        {
            var connection = @event.Source;

            switch (@event.State)
            {
            case HTTPConnectionStates.Recycle:
                HostManager.GetHost(connection.LastProcessedUri.Host)
                .GetHostDefinition(connection.ServerAddress)
                .RecycleConnection(connection)
                .TryToSendQueuedRequests();

                break;

            case HTTPConnectionStates.WaitForProtocolShutdown:
                HostManager.GetHost(connection.LastProcessedUri.Host)
                .GetHostDefinition(connection.ServerAddress)
                .RemoveConnection(connection, @event.State);
                break;

            case HTTPConnectionStates.Closed:
                HostManager.GetHost(connection.LastProcessedUri.Host)
                .GetHostDefinition(connection.ServerAddress)
                .RemoveConnection(connection, @event.State)
                .TryToSendQueuedRequests();

                break;
            }
        }
#pragma warning restore

        public static void EnqueueConnectionEvent(ConnectionEventInfo @event)
        {
            connectionEventQueue.Enqueue(@event);
        }