public override void RequestHeaderAvailable( IHttpRequest request, ISessionContext context )
        {
            Contract.Requires(context.ClientConnection != null);

            ServiceLog.Logger.Verbose(
                () => string.Format(
                    "{0}\r\n========================\r\n{1}\r\n========================\r\n",
                    context.Id, Encoding.UTF8.GetString(request.GetBuffer())));

            //string filter = _filter.EvaluateConnectionFilters(request, context.ClientConnection.ConnectionId);

            //if (filter != null)
            //{
            //    ServiceLog.Logger.Info("{0} Connection filtered. Sending response to client.", context.Id);
            //    context.SendClientData(Encoding.UTF8.GetBytes(filter));
            //    context.ChangeState(SessionStateType.Unconnected);
            //}
            //else
            {
                if (request.IsSsl)
                {
                    context.ChangeState(SessionStateType.Https);
                }
                else
                {
                    string host;
                    int port;

                    if (SessionStateUtils.TryParseAddress(request, out host, out port))
                    {
                        ServiceLog.Logger.Info("{0} Attempting to connect to remote host: [{1}] [{2}]", context.Id, host, port);

                        context.BeginConnectToRemoteHost(host, port);
                    }
                    else
                    {
                        throw new InvalidDataException("Unable to parse host address from HTTP request");
                    }
                }

            }
        }
        public override void TransitionToState(ISessionContext context)
        {
            context.CloseServerConnection();

            if (context.RecentRequestHeader.IsSsl)
            {
                context.ChangeState(SessionStateType.Https);
            }
            else
            {
                string host;
                int port;

                if (SessionStateUtils.TryParseAddress(context.RecentRequestHeader, out host, out port))
                {
                    context.BeginConnectToRemoteHost(host, port);
                }
                else
                {
                    ServiceLog.Logger.Error("{0} Unable to parse host address: {1}", context.Id, Encoding.UTF8.GetString(context.RecentRequestHeader.GetBuffer()));
                    context.Reset();
                }
            }
        }