Skip to content
Myr

Merge pull request #4349 from alvarogzp/patch-1

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix case-insensitive comparison in Session.get_adapter

authored by Cory Benfield · committed by GitHub · parents db9da3e, 2afc1cb · Browse files · 2 files+39 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+39 added−1 removed

  • tests:+38 added−0 removed
  • other:+1 added−1 removed

2 files+39 added−1 removed

modified:requests/sessions.py+1 added-1 removed
694 unmodified lines
695 :rtype: requests.adapters.BaseAdapter696 """697 for (prefix, adapter) in self.adapters.items():698699 if url.lower().startswith(prefix):699 if url.lower().startswith(prefix.lower()):700 return adapter701702 # Nothing matches :-/703 raise InvalidSchema("No connection adapters were found for '%s'" % url)
34 unmodified lines
modified:tests/test_requests.py+38 added
1349 unmodified lines
1350 s2.mount('https://', HTTPAdapter())1351 assert 'http://' in s2.adapters1352 assert 'https://' in s2.adapters13531354 def test_session_get_adapter_prefix_matching(self, httpbin):1355 prefix = 'https://example.com'1356 more_specific_prefix = prefix + '/some/path'13571358 url_matching_only_prefix = prefix + '/another/path'1359 url_matching_more_specific_prefix = more_specific_prefix + '/longer/path'1360 url_not_matching_prefix = 'https://another.example.com/'13611362 s = requests.Session()1363 prefix_adapter = HTTPAdapter()1364 more_specific_prefix_adapter = HTTPAdapter()1365 s.mount(prefix, prefix_adapter)1366 s.mount(more_specific_prefix, more_specific_prefix_adapter)13671368 assert s.get_adapter(url_matching_only_prefix) is prefix_adapter1369 assert s.get_adapter(url_matching_more_specific_prefix) is more_specific_prefix_adapter1370 assert s.get_adapter(url_not_matching_prefix) not in (prefix_adapter, more_specific_prefix_adapter)13711372 def test_session_get_adapter_prefix_matching_mixed_case(self, httpbin):1373 mixed_case_prefix = 'hTtPs://eXamPle.CoM/MixEd_CAse_PREfix'1374 url_matching_prefix = mixed_case_prefix + '/full_url'13751376 s = requests.Session()1377 my_adapter = HTTPAdapter()1378 s.mount(mixed_case_prefix, my_adapter)13791380 assert s.get_adapter(url_matching_prefix) is my_adapter13811382 def test_session_get_adapter_prefix_matching_is_case_insensitive(self, httpbin):1383 mixed_case_prefix = 'hTtPs://eXamPle.CoM/MixEd_CAse_PREfix'1384 url_matching_prefix_with_different_case = 'HtTpS://exaMPLe.cOm/MiXeD_caSE_preFIX/another_url'13851386 s = requests.Session()1387 my_adapter = HTTPAdapter()1388 s.mount(mixed_case_prefix, my_adapter)13891390 assert s.get_adapter(url_matching_prefix_with_different_case) is my_adapter13911392 def test_header_remove_is_case_insensitive(self, httpbin):1393 # From issue #13211394 s = requests.Session()1395 s.headers['foo'] = 'bar'
1032 unmodified lines