title: Laravel Http Client with proxy working only on first request
body: <ol>
  <li>Make a get request to some URL using the <code>\Illuminate\Support\Facades\Http</code> with a proxy setup;</li>
  <li>The request goes through the proxy and hits the destination server. I can see the IP received belongs to the proxy and not to my machine. (Everything working fine so far);</li>
  <li>Make that same request again;</li>
  <li>The IP received by the destination server belongs to my machine. The proxy is not working anymore.</li>
  </ol>
  <p>See the tinker output:</p>
  <pre><code>my-aws-docker-user@fb14363368ff:/var/www/html$ php artisan tinker
  Psy Shell v0.10.4 (PHP 7.4.10 — cli) by Justin Hileman
  
  &gt;&gt;&gt; $credentials = &quot;http://54.234.XXX.XX:808&quot;;
  =&gt; &quot;http://54.234.XXX.XX:808&quot;
  
  &gt;&gt;&gt; \Illuminate\Support\Facades\Http::withOptions(['proxy' =&gt; $credentials, 'debug' =&gt; true])-&gt;get('https://api.ipify.org/')-&gt;body();
  
  * Expire in 0 ms for 6 (transfer 0x560ff2ad7d30)
  * Expire in 150000 ms for 2 (transfer 0x560ff2ad7d30)
  *   Trying 54.234.XXX.XX...
  * TCP_NODELAY set
  * Expire in 200 ms for 4 (transfer 0x560ff2ad7d30)
  * Connected to 54.234.XX.XX (54.234.XXX.XX) port 808 (#0)
  * allocate connect buffer!
  * Establish HTTP proxy tunnel to api.ipify.org:443
  &gt; CONNECT api.ipify.org:443 HTTP/1.1
  Host: api.ipify.org:443
  Proxy-Connection: Keep-Alive
  
  &lt; HTTP/1.1 200 Connection established
  &lt; Proxy-agent: CCProxy
  &lt;
  * Proxy replied 200 to CONNECT request
  * CONNECT phase completed!
  * ALPN, offering http/1.1
  * successfully set certificate verify locations:
  *   CAfile: none
    CApath: /etc/ssl/certs
  * CONNECT phase completed!
  * CONNECT phase completed!
  * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
  * ALPN, server did not agree to a protocol
  * Server certificate:
  *  subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.ipify.org
  *  start date: Jan 24 00:00:00 2018 GMT
  *  expire date: Jan 23 23:59:59 2021 GMT
  *  subjectAltName: host &quot;api.ipify.org&quot; matched cert's &quot;*.ipify.org&quot;
  *  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
  *  SSL certificate verify ok.
  &gt; GET / HTTP/1.1
  Host: api.ipify.org
  User-Agent: GuzzleHttp/6.5.5 curl/7.64.0 PHP/7.4.10
  
  &lt; HTTP/1.1 200 OK
  &lt; Server: Cowboy
  &lt; Connection: keep-alive
  &lt; Content-Type: text/plain
  &lt; Vary: Origin
  &lt; Date: Tue, 29 Sep 2020 20:10:22 GMT
  &lt; Content-Length: 13
  &lt; Via: 1.1 vegur
  &lt;
  * Connection #0 to host 54.234.XXX.XX left intact
  
  =&gt; &quot;54.234.XXX.XX&quot; // This is my proxy IP
  </code></pre>
  <p>The first request works good. Now performing the same one in the same tinker session (arrow up + enter):</p>
  <pre><code>&gt;&gt;&gt; \Illuminate\Support\Facades\Http::withOptions(['proxy' =&gt; $credentials, 'debug' =&gt; true])-&gt;get('https://api.ipify.org/')-&gt;body();
  
  * Expire in 0 ms for 6 (transfer 0x560ff2addc90)
  * Expire in 150000 ms for 2 (transfer 0x560ff2addc90)
  * Expire in 1 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 1 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 0 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 1 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 1 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 1 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 1 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 2 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 3 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 3 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 3 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 3 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 5 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 5 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 4 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 6 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 6 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 8 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 7 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 7 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 8 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 8 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 8 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 16 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 10 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 10 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 16 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 11 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 11 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 16 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 14 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 14 ms for 1 (transfer 0x560ff2addc90)
  * Expire in 15 ms for 1 (transfer 0x560ff2addc90)
  *   Trying 23.21.203.47...
  * TCP_NODELAY set
  * Expire in 74977 ms for 3 (transfer 0x560ff2addc90)
  * Expire in 200 ms for 4 (transfer 0x560ff2addc90)
  * Connected to api.ipify.org (23.21.203.47) port 443 (#0)
  * ALPN, offering http/1.1
  * successfully set certificate verify locations:
  *   CAfile: none
    CApath: /etc/ssl/certs
  * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
  * ALPN, server did not agree to a protocol
  * Server certificate:
  *  subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.ipify.org
  *  start date: Jan 24 00:00:00 2018 GMT
  *  expire date: Jan 23 23:59:59 2021 GMT
  *  subjectAltName: host &quot;api.ipify.org&quot; matched cert's &quot;*.ipify.org&quot;
  *  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
  *  SSL certificate verify ok.
  &gt; GET / HTTP/1.1
  Host: api.ipify.org
  User-Agent: GuzzleHttp/6.5.5 curl/7.64.0 PHP/7.4.10
  
  &lt; HTTP/1.1 200 OK
  &lt; Server: Cowboy
  &lt; Connection: keep-alive
  &lt; Content-Type: text/plain
  &lt; Vary: Origin
  &lt; Date: Tue, 29 Sep 2020 20:11:26 GMT
  &lt; Content-Length: 11
  &lt; Via: 1.1 vegur
  &lt;
  * Connection #0 to host api.ipify.org left intact
  
  =&gt; &quot;3.92.XX.XXX&quot; // This is my instance IP
  </code></pre>
  <ul>
  <li>The application is running in a docker container hosted in a EC2 Instance on AWS;</li>
  <li>The problem seems to occur only on AWS;</li>
  <li>The proxy server is working fine. We tried Squid Cache Proxy and CCProxy and both have the same issue;</li>
  <li>Performing a cURL request from the docker container on AWS also works (see logs below).</li>
  </ul>
  <pre><code>my-aws-docker-user@fb14363368ff:/var/www/html$ curl -x http://54.234.XXX.XX:808 -L https://api.ipify.org/ -v
  * Expire in 0 ms for 6 (transfer 0x55abb8f38f50)
  *   Trying 54.234.XXX.XX...
  * TCP_NODELAY set
  * Expire in 200 ms for 4 (transfer 0x55abb8f38f50)
  * Connected to 54.234.XXX.XX (54.234.XXX.XX) port 808 (#0)
  * allocate connect buffer!
  * Establish HTTP proxy tunnel to api.ipify.org:443
  &gt; CONNECT api.ipify.org:443 HTTP/1.1
  &gt; Host: api.ipify.org:443
  &gt; User-Agent: curl/7.64.0
  &gt; Proxy-Connection: Keep-Alive
  &gt;
  &lt; HTTP/1.1 200 Connection established
  &lt; Proxy-agent: CCProxy
  &lt;
  * Proxy replied 200 to CONNECT request
  * CONNECT phase completed!
  * ALPN, offering h2
  * ALPN, offering http/1.1
  * successfully set certificate verify locations:
  *   CAfile: none
    CApath: /etc/ssl/certs
  * TLSv1.3 (OUT), TLS handshake, Client hello (1):
  * CONNECT phase completed!
  * CONNECT phase completed!
  * TLSv1.3 (IN), TLS handshake, Server hello (2):
  * TLSv1.2 (IN), TLS handshake, Certificate (11):
  * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  * TLSv1.2 (IN), TLS handshake, Server finished (14):
  * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
  * TLSv1.2 (OUT), TLS handshake, Finished (20):
  * TLSv1.2 (IN), TLS handshake, Finished (20):
  * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
  * ALPN, server did not agree to a protocol
  * Server certificate:
  *  subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.ipify.org
  *  start date: Jan 24 00:00:00 2018 GMT
  *  expire date: Jan 23 23:59:59 2021 GMT
  *  subjectAltName: host &quot;api.ipify.org&quot; matched cert's &quot;*.ipify.org&quot;
  *  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
  *  SSL certificate verify ok.
  &gt; GET / HTTP/1.1
  &gt; Host: api.ipify.org
  &gt; User-Agent: curl/7.64.0
  &gt; Accept: */*
  &gt;
  &lt; HTTP/1.1 200 OK
  &lt; Server: Cowboy
  &lt; Connection: keep-alive
  &lt; Content-Type: text/plain
  &lt; Vary: Origin
  &lt; Date: Tue, 29 Sep 2020 20:32:25 GMT
  &lt; Content-Length: 13
  &lt; Via: 1.1 vegur
  &lt;
  * Connection #0 to host 54.234.XXX.XX left intact
  54.234.XXX.XX // This is my proxy IP
  </code></pre>