void ServerParserBodyAvailable(byte[] data, ISessionContext context)
        {
            byte[] filter = Filter.EvaluateResponseFiltersWithBody(context.RecentResponseHeader,
                                                                   context.ClientConnection.ConnectionId,
                                                                   data);

            // Wait until now to send the header in case the filter modifies it, such as updating content-length.
            context.SendClientData(context.RecentResponseHeader.GetBuffer());

            // The body changed. Send the modified body and not the original body. Disconnect afterwards.
            if (filter != data)
            {
                ServiceLog.Logger.Info("{0} *** PERFORMANCE HIT *** Response filter activated. Body modified.", context.Id);

                if (filter.Length > 0)
                {
                    context.SendClientData(filter);
                    context.ChangeState(SessionStateType.Unconnected);
                }
            }
            else
            {
                // Change back to the normal connnection state
                context.ChangeState(SessionStateType.Connected);
                context.SendClientData(data);
            }
        }
Exemple #2
0
        public override void TransitionToState( ISessionContext context )
        {
            Contract.Requires( context.ClientConnection != null );
            Contract.Requires( context.ServerConnection == null );

            context.SendClientData(Encoding.UTF8.GetBytes("HTTPS not supported"));
            context.Reset();

            //// TODO: is this required?
            //context.ClientConnection.CancelPendingReceive();
            //context.UnwireClientParserEvents();

            //ServiceLog.Logger.Info( "{0} Establishing HTTPS tunnel", context.Id );

            //string[] pathTokens = context.RecentRequestHeader.Path.Split( ':' );

            //if ( pathTokens.Length == 2 )
            //{
            //    context.ConnectToRemoteHost( pathTokens[0], Int32.Parse( pathTokens[1] ) );
            //}
            //else
            //{
            //    throw new InvalidDataException( "Unable to determine SSL host address" );
            //}

            //_context = context;
        }
Exemple #3
0
        public override void TransitionToState(ISessionContext context)
        {
            //context.UnwireClientParserEvents();

            if (context.ClientConnection != null)
            {
                context.SendClientData(Encoding.UTF8.GetBytes("HTTP/1.1 200 OK\r\nContent-length: 11\r\n\r\nProxy error"));
            }

            context.Reset();
        }
        public override void ResponseHeaderAvailable(IHttpResponse response, ISessionContext context)
        {
            ServiceLog.Logger.Verbose(() => string.Format("{0}\r\n===RESPONSE=============\r\n{1}\r\n========================\r\n", context.Id, Encoding.UTF8.GetString(response.GetBuffer())));

            context.SendClientData(response.GetBuffer());

            //// Consult the response filters to see if any are interested in the entire body.
            //// Don't build the response body unless we have to; it's expensive.
            //// If any filters can make the judgement now, before we read the body, then use their response to
            //// short-circuit the body evaluation.
            //string filterResponse;
            //if (_filter.TryEvaluateResponseFilters(response,
            //                                         context.ClientConnection.ConnectionId,
            //                                         out filterResponse))
            //{
            //    // Filter active and does not need HTTP body
            //    if (filterResponse != null)
            //    {
            //        ServiceLog.Logger.Info("{0} *** PERFORMANCE HIT *** Response filter blocking content", context.Id);

            //        // Stop listening for more data from the server. We are creating our own response.
            //        // The session will terminate once this response is sent to the client.
            //        context.ChangeState(SessionStateType.ResponseHeaderFilter);
            //        context.SendClientData(Encoding.UTF8.GetBytes(filterResponse));
            //    }
            //    else
            //    {
            //        // Normal behavior. No filter activated.
            //        context.SendClientData(response.GetBuffer());
            //    }
            //}
            //else
            //{
            //    // Prepare to receive the entire HTTP body
            //    ServiceLog.Logger.Info("{0} *** PERFORMANCE HIT *** Response filter requires entire body. Building HTTP body.", context.Id);
            //    context.ChangeState(SessionStateType.ResponseBodyFilter);
            //}
        }