title: HttpRoutePlanner - How does it work with an HTTPS Proxy
body: <p>I have an HTTPS proxy set up so that HTTP clients can send plain HTTP requests securely to the proxy. For example, a client can send an encrypted HTTP GET request to the proxy, which will remove the encryption and send the plain HTTP GET request to the end-site.</p>
  
  <p>I learned that this is not a common set up and only Google Chrome has in-built features to support such a scenario. (Info here - <a href="http://wiki.squid-cache.org/Features/HTTPS#Encrypted_browser-Squid_connection" rel="nofollow noreferrer">http://wiki.squid-cache.org/Features/HTTPS#Encrypted_browser-Squid_connection</a>). I have made Google Chrome work with my HTTPS proxy and hence there is no trouble on the proxy side.</p>
  
  <p>I wish to write an HTTP Client that will encrypt all requests to my HTTPS Proxy. I tried setting an HTTPS proxy to DefaultHttpClient this way - </p>
  
  <pre><code>DefaultHttpClient dhc = new DefaultHttpClient();
  HttpHost proxy = new HttpHost("192.168.2.3", 8181, "https"); //NOTE : https
  dhc.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
  </code></pre>
  
  <p>Then trying to execute any request gives me an SSLPeerUnverifiedException. I do not understand the reason why. </p>
  
  <p>During my exploration of the DefaultHttpClient API, I came across HttpRoutePlanner and HttpRoute with which we can specify whether the connection to proxies should be encrypted or not. However, I am unable to make this work.</p>
  
  <p>Here is a diagram that explains my setup by differentiating it with a HTTP Proxy setup - </p>
  
  <p><strong>HTTP Proxy:</strong></p>
  
  <pre><code>HTTP Client &lt;------- Plain Text GET, POST Requests -------&gt; HTTP Proxy &lt;------- Plain Text GET, POST Requests -------&gt; HTTP End-Site
  
  HTTP Client &lt;------- Plain Text CONNECT Requests -------&gt; HTTP Proxy &lt;------- Plain Text CONNECT Requests -------&gt; HTTPS End-Site
  </code></pre>
  
  <p>NOTE: For HTTPS End-Sites, only the CONNECT Request is seen by the proxy. Then an SSL Tunnel is established between the Client and End-Site</p>
  
  <p><strong>HTTPS Proxy:</strong></p>
  
  <pre><code>HTTP Client &lt;------- Encrypted GET, POST Requests -------&gt; HTTPS Proxy &lt;-------- Plain Text GET, POST Requests --------&gt;  HTTP End-Site
  
  HTTP Client &lt;------- Encrypted CONNECT Requests -------&gt; HTTPS Proxy &lt;------- Plain Text CONNECT Requests -------&gt; HTTPS End-Site
  </code></pre>
  
  <p>NOTE: For HTTPS End-Sites, only the initial CONNECT Request should be encrypted to the proxy. The subsequent request will anyway be tunnelled.</p>
  
  <p>Can anybody please let me know how I can achieve this goal? I believe HttpRoutePlanner should help, but I don't know how.</p>