<p dir="auto">This question came out when I tried to validate some proxies.<br>
If  proxy-scheme is uppercase as follows, it will return 200. (The host of proxy is not a true one.)<br>
import requests<br>
proxy = {<br>
'HTTP': '<a href="HTTP://111.1.11.1:8000" rel="nofollow">HTTP://111.1.11.1:8000</a>'<br>
}<br>
r = requests.get('<a href="http://www.sina.com',proxies" rel="nofollow">http://www.sina.com',proxies</a> = proxy)<br>
print (r.status_code)</p>
<p dir="auto">However, if changing 'HTTP' to 'http', it will raise an error about httpconnectionerror.<br>
So, it is confused me that proxy-scheme is case sensitivity or not? Or something went wrong about my code ?</p>
<p dir="auto">Hoping to receive your instruction.</p>
<p dir="auto">Hi there,</p>
<p dir="auto">First off, Requests is awesome. Thank you for the great library!</p>
<p dir="auto">I'm writing a script that places a series of requests and manually follows some redirects, and one of the redirects is to a URL that starts with "HTTPS" (that is, the protocol is uppercase, like <a href="HTTPS://www.example.com" rel="nofollow">HTTPS://www.example.com</a> instead of <a href="https://www.example.com" rel="nofollow">https://www.example.com</a>). It would seem that Requests generates the wrong request when the following three conditions are met:</p>
<ol dir="auto">
<li>The protocol is HTTPS.</li>
<li>The protocol contains one or more uppercase letters. (e.g. "HTTPS", "httpS", "hTTps", "Https", etc.)</li>
<li>Proxies are being used.</li>
</ol>
<p dir="auto">I wrote a test script that uses a Session to GET <a href="http://www.example.com" rel="nofollow">www.example.com</a> with variations in case for both http and https protocols, and here are the results:</p>
<table role="table">
<thead>
<tr>
<th>proto</th>
<th>proxies</th>
<th>result</th>
</tr>
</thead>
<tbody>
<tr>
<td>http</td>
<td>no</td>
<td>[OK]</td>
</tr>
<tr>
<td>htTp</td>
<td>no</td>
<td>[OK]</td>
</tr>
<tr>
<td>HTTP</td>
<td>no</td>
<td>[OK]</td>
</tr>
<tr>
<td>https</td>
<td>no</td>
<td>[OK]</td>
</tr>
<tr>
<td>HTTPS</td>
<td>no</td>
<td>[OK]</td>
</tr>
<tr>
<td>htTps</td>
<td>no</td>
<td>[OK]</td>
</tr>
<tr>
<td>httpS</td>
<td>no</td>
<td>[OK]</td>
</tr>
<tr>
<td>Https</td>
<td>no</td>
<td>[OK]</td>
</tr>
<tr>
<td>http</td>
<td>YES</td>
<td>[OK]</td>
</tr>
<tr>
<td>htTp</td>
<td>YES</td>
<td>[OK]</td>
</tr>
<tr>
<td>HTTP</td>
<td>YES</td>
<td>[OK]</td>
</tr>
<tr>
<td>https</td>
<td>YES</td>
<td>[OK]</td>
</tr>
<tr>
<td>HTTPS</td>
<td>YES</td>
<td>[ERROR]</td>
</tr>
<tr>
<td>htTps</td>
<td>YES</td>
<td>[ERROR]</td>
</tr>
<tr>
<td>httpS</td>
<td>YES</td>
<td>[ERROR]</td>
</tr>
<tr>
<td>Https</td>
<td>YES</td>
<td>[ERROR]</td>
</tr>
</tbody>
</table>
<p dir="auto">In the ERROR case, my proxy (Burp) was generating the following error:<br>
<strong>Error</strong><br>
Invalid client request received: First line of request did not contain an absolute URL - try enabling invisible proxy support.<br>
GET / HTTP/1.1<br>
Host: localhost:8080<br>
Connection: keep-alive<br>
Accept-Encoding: gzip, deflate<br>
Accept: <em>/</em><br>
User-Agent: python-requests/2.9.1</p>
<p dir="auto">The issue can be replicated with the following couple lines of code:<br>
<code class="notranslate">import requests</code><br>
<code class="notranslate">requests.request('GET', 'HTTPS://www.example.com/test', proxies=dict(http='localhost:8080', https='localhost:8080'))</code></p>
<p dir="auto">What happens will depend on your proxy. With Burp, when errors are given back as valid HTTP responses, the above will result in a 200 OK response object, and when you inspect the content of the response, you'll see Burp's error. However, if you suppress Burp errors, then Burp returns an empty response, causing requests to raise a ConnectionError exception:<br>
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))</p>
<p dir="auto">Thank you for your time!</p>
<p dir="auto">Best Regards,<br>
-Justin</p>