SSL proxy

Add support for SSL proxy. Also add more error event listeners for better error handling.