Extensible man in the middle HTTP proxy with SSL support. It was written because I need a way to monitor and possibly stub some browser request in selenium tests. It also available as NuGet Package
Setup HTTP proxy:
var httpProxyServer = new HttpProxyServer("localhost", new HttpProxy());
httpProxyServer.Start().WaitOne();
// do stuff
httpProxyServer.stop();
Setup SSL proxy:
var certificate = new X509Certificate2("path_to_sertificate", "password");
var sslProxyServer = new HttpProxyServer("localhost", new SslProxy(certificate));
sslProxyServer.start();
// do ssl stuff
sslProxyServer.stop();
Request are processed in 5 stages:
- receive request from client
- connect to destination server
- send request to server and receive response
- send response back to client
- complete processing and close connections
It is possible to add additional behavior to any stage with delegates:
var httpProxy = new HttpProxy(){
OnRequestReceived = context => {},
OnServerConnected = context => {},
OnResponseReceived = context => {},
OnResponseSent = context => {},
OnProcessingComplete = context => {}
};
Context stores request information during processing single request. What you can possibly do with it ?
- modify request and response headers
- modify request and response body
- respond by yourself on behalf of destination server
- ...or something in between
Take a look at console app and tests for usage example.