I'm writing a simple program in Java that receives connection requests from a browser (like Firefox), parses the request for statistical info, then forwards the request to the original destination. The program then reads the response from the destination, parses the response for statistical info, then forwards the response to the browser.
The pseudo code of this operation is as follows:
// Accept connection from browser and read request
1. Socket browserConnection = serverSocket.accept();
2. browserConnection.getInputStream().read(buffer);
3. SocketInetAddress destInetAddress = parseHttpRequest(buffer);
// Connect to destination and forward request
4. Socket destConnection = new Socket(destInetAddress);
5. destConnection.getOutputStream().write(buffer);
// Read response from destination
6. destConnection.getInputStream().read(buffer);
7. parseHttpResponse(buffer);
// Forward response to browser
8. browserConnection.getOutputStream().write(buffer);
This works well with HTTP connections, but I'm getting connection reset for HTTPS connections.
NOTE : I know the difference between HTTP and HTTPS connections, that unlike HTTP, it's NOT just a one-time send and then some receives. My code for HTTPS reads as much as needed, and also writes as much as needed.
Why am I getting connection resets from any HTTPS server (e.g. https://www.google.com, https://www.comodo.com, etc.) I try to connect ?!