I am trying to create a proxy server to handle a local request.
For example, grab a print request for a web browser and send them to the appropriate LAN printer.
My idea so far is to host the FiddlerCore mechanism in a Windows service.
This is my code:
private static void Main()
{
FiddlerApplication.OnNotification += (sender, e) => Console.WriteLine("** NotifyUser: " + e.NotifyString);
FiddlerApplication.Log.OnLogString += (sender, e) => Console.WriteLine("** LogString: " + e.LogString);
FiddlerApplication.BeforeRequest += oSession => { Console.WriteLine("Before request for:\t" + oSession.fullUrl); oSession.bBufferResponse = true; ParseRequest(oSession); };
FiddlerApplication.BeforeResponse += oSession => Console.WriteLine("{0}:HTTP {1} for {2}", oSession.id, oSession.responseCode, oSession.fullUrl);
FiddlerApplication.AfterSessionComplete += oSession => Console.WriteLine("Finished session:\t" + oSession.fullUrl);
Console.CancelKeyPress += Console_CancelKeyPress;
Console.WriteLine("Starting FiddlerCore...");
CONFIG.IgnoreServerCertErrors = true;
FiddlerApplication.Startup(8877, true, true);
Console.WriteLine("Hit CTRL+C to end session.");
Object forever = new Object();
lock (forever)
{
Monitor.Wait(forever);
}
}
private static void ParseRequest(Session oSession)
{
switch (oSession.host)
{
case "localhost.":
Console.WriteLine("Handling local request...");
break;
}
}
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
Console.WriteLine("Shutting down...");
FiddlerApplication.Shutdown();
Thread.Sleep(750);
}
My question:
A function ParseRequestcan recognize local requests (i.e. http://localhost./print?whatever ), but how can I stop the proxy server from forwarding them (parsing and executing a print request, but not getting a 404 page) ?
source
share