( new WaitCallback(ProxyServer.ProcessClient), client)) TcpClient client = listener.AcceptTcpClient() wait for server to finish processing current connections. stop listening for incoming connections _listenerThread = new Thread( new ParameterizedThreadStart(Listen)) _listener = new TcpListener(IPAddress.Loopback, 8888) This thread's job will be to listen for incoming connections, and then spawn a new thread to handle processing, thus allowing the listening thread to continue listening for new connections without blocking while one client is processed. We'll use the object to start listening for connections in a separate thread. In the mean time, we'll send the same request to the destination HTTPS server.įirst, let's look at creating a server that can handle multiple concurrent TCP connections. The most important part about this code is that when the client asks for a CONNECT, instead of just passing TCP traffic, we're going to handle an SSL handshake and establish an SSL session and receive a request from the client. The class is utilized to handle all the heavy lifting. It essentially performs a "man-in-the-middle" on the HTTP client to dump and debug HTTP traffic. If you are familiar with fiddler, then you already know how this proxy server works. By using this code or the executable found in this article, you are taking responsibility for the data which may be collected through its use. Do not use this server in any environment which has users that are unaware of its use. The author does not intend for this code or the executable to be used in any way that may compromise someone's sensitive information. I've added a simple caching mechanism, and have simplified the code by ignoring http/1.1 requests for keeping connections alive, etc.ĭisclaimer: Understand that this code is for debugging and testing purposes only. This article will show you how to implement a multithreaded HTTP proxy server in C# with a non-standard proxy server feature of terminating and then proxying HTTPS traffic.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |