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); } }
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(); } } }
public override void ServerConnectionEstablished(ISessionContext context) { context.ChangeState(SessionStateType.Connected); context.SendServerData(context.RecentRequestHeader.GetBuffer()); }
public override void SentFullServerResponseToClient( IHttpResponse response, ISessionContext context ) { context.ChangeState( SessionStateType.Unconnected ); }
public override void ServerConnectionEstablished(ISessionContext context) { context.ChangeState(SessionStateType.Connected); }