Merge pull request #1385 from ViktorHaag/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Cope with mixed-case URL schemes (like 'HTTP') by lower-ifying 'url' string before calling startswith() on it
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 60b1a0b, 01993d2 · Browse files · 3 files·+33 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+33 added−5 removed
- other:+33 added−5 removed
Provenance
- Commit
d4c4610- Tree
711e5ca- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
60b1a0b- Parent 2
01993d2
3 files changed+33 added−5 removed
modified:requests/adapters.py+4 added-4 removed
116 unmodified lines117 :param url: The requested URL.118 :param verify: Whether we should actually verify the certificate.119 :param cert: The SSL certificate to verify.120 """121- if url.startswith('https') and verify:121+ if url.lower().startswith('https') and verify:122 123 cert_loc = None124 125 # Allow self-specified cert location.63 unmodified lines189 :param url: The URL to connect to.190 :param proxies: (optional) A Requests-style dictionary of proxies used on this request.191 """192 proxies = proxies or {}193- proxy = proxies.get(urlparse(url).scheme)193+ proxy = proxies.get(urlparse(url.lower()).scheme)194 195 if proxy:196- proxy = prepend_scheme_if_needed(proxy, urlparse(url).scheme)196+ proxy = prepend_scheme_if_needed(proxy, urlparse(url.lower()).scheme)197 conn = ProxyManager(self.poolmanager.connection_from_url(proxy))198 else:199- conn = self.poolmanager.connection_from_url(url)199+ conn = self.poolmanager.connection_from_url(url.lower())200 201 return conn202 203 def close(self):139 unmodified linesmodified:requests/sessions.py+1 added-1 removed
465 unmodified lines466 def get_adapter(self, url):467 """Returns the appropriate connnection adapter for the given URL."""468 for (prefix, adapter) in self.adapters.items():469 470- if url.startswith(prefix):470+ if url.lower().startswith(prefix):471 return adapter472 473 # Nothing matches :-/474 raise InvalidSchema("No connection adapters were found for '%s'" % url)27 unmodified linesmodified:test_requests.py+28 added
85 unmodified lines86 "http://example.com/path?key=value#fragment", params={"a": "b"}).prepare()87 self.assertEqual(request.url,88 "http://example.com/path?key=value&a=b#fragment")89 90+ def test_mixed_case_scheme_acceptable(self):91+ s = requests.Session()92+ r = requests.Request('GET', 'http://httpbin.org/get')93+ r = s.send(r.prepare())94+ self.assertEqual(r.status_code,200)95+ s = requests.Session()96+ r = requests.Request('GET', 'HTTP://httpbin.org/get')97+ r = s.send(r.prepare())98+ self.assertEqual(r.status_code,200)99+ r = requests.Request('GET', 'hTTp://httpbin.org/get')100+ r = s.send(r.prepare())101+ self.assertEqual(r.status_code,200)102+ r = requests.Request('GET', 'HttP://httpbin.org/get')103+ r = s.send(r.prepare())104+ self.assertEqual(r.status_code,200)105+ r = requests.Request('GET', 'https://httpbin.org/get')106+ r = s.send(r.prepare())107+ self.assertEqual(r.status_code,200)108+ r = requests.Request('GET', 'HTTPS://httpbin.org/get')109+ r = s.send(r.prepare())110+ self.assertEqual(r.status_code,200)111+ r = requests.Request('GET', 'hTTps://httpbin.org/get')112+ r = s.send(r.prepare())113+ self.assertEqual(r.status_code,200)114+ r = requests.Request('GET', 'HttPs://httpbin.org/get')115+ r = s.send(r.prepare())116+ self.assertEqual(r.status_code,200)117+118 def test_HTTP_200_OK_GET_ALTERNATIVE(self):119 r = requests.Request('GET', httpbin('get'))120 s = requests.Session()121 613 unmodified lines