Hi Can someone tell me what's involved creating a minimal effort http proxy like apache's tcpmon. I want my simple application just to sit and wait and scan a port, for example 8080 on localhost, for http requests which I sent to that proxy by setting System.setProperty("http.proxyHost", "127.0.0.1") and System.setProperty("http.proxyPort", "8080"). If it get's a request, use a BufferedReader to read the request and send it on. Same for the reply. My proxy should be able to receive it, show it and forward it to the original sender. Is this hard to implement? Thanks
Hi Mr. Rice, Welcome to JavaRanch! We don't have too many rules round these parts, but we do have our naming policy, which requires that your display name not be a fictitious name. Pleae head over here and update yours, pronto. Thanks, pardner!
Depends on how well you want it to work, I suppose. Basically, you'd open a ServerSocket. Each incoming proxy request should look something like GET http://server:port/file.html HTTP/1.0 Header1: something Header2: something else ... (blank line) The GET can be POST instead, in which case the blank line will be followed by POST data; a Content-Length: header will specify how much. This is just one of potentially many headers that could be meaningful to the proxy server. In any case, when you get a connection on the ServerSocket, you read the first line as text, parse out the URL, open a connection with a Socket, pass along the request and the headers (and optional data). Then you'll get back a response code line line HTTP/1.1 200 OK or HTTP/1.1 404 File Not Found some headers, a blank line, and then the document. You can just pass everything back to the Socket for the incoming connection. Now, there's also HTTPS, which adds a few wrinkles of its own. Maybe you could just use Muffin? [ March 16, 2004: Message edited by: Ernest Friedman-Hill ]
Joined: Mar 16, 2004
No me not Muffin. Why? Bad Spammer? Ok, thanks for your answer. I now have something like that that nearly works so thanks for your help. Can anyone point me to some open source that implements the simplest proxy, i.e. just intercepting and forwarding. I pressume there will be a seperate thread for each incoming request which handles the communication. So I have updated my name. Rice