Skip to content
Myr

Clear any pooled proxy connections

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

As well as clearing any pooled direct connections, iterate over any ProxyManager objects and clear any pooled proxy connections there as well.

authored by Matt Dainty · committed by Matt Dainty · parent 4a716e0 · Browse files · 3 files+16 added−2 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+16 added−2 removed

  • tests:+11 added−0 removed
  • other:+5 added−2 removed

3 files+16 added−2 removed

modified:requests/adapters.py+4 added-2 removed
262 unmodified lines
263264 def close(self):265 """Disposes of any internal state.266267 Currently, this just closes the PoolManager, which closes pooled268 connections.267 Currently, this closes the PoolManager and any active ProxyManager,268 which closes any pooled connections.269 """270 self.poolmanager.clear()271 for proxy in self.proxy_manager.values():272 proxy.clear()273274 def request_url(self, request, proxies):275 """Obtain the url to use when making the final request.276
182 unmodified lines
modified:tests/test_requests.py+11 added
1186 unmodified lines
11871188 next(r.iter_lines())1189 assert len(list(r.iter_lines())) == 311901191 def test_session_close_proxy_clear(self, mocker):1192 proxies = {1193 'one': mocker.Mock(),1194 'two': mocker.Mock(),1195 }1196 session = requests.Session()1197 mocker.patch.dict(session.adapters['http://'].proxy_manager, proxies)1198 session.close()1199 proxies['one'].clear.assert_called_once_with()1200 proxies['two'].clear.assert_called_once_with()120112021203class TestCaseInsensitiveDict:12041205 @pytest.mark.parametrize(1206 'cid', (
382 unmodified lines
modified:requirements.txt+1 added
11 unmodified lines
12Pygments==2.1.113pytest==2.8.714pytest-cov==2.2.115pytest-httpbin==0.2.016pytest-mock==0.11.017pytz==2015.718six==1.10.019snowballstemmer==1.2.120Sphinx==1.3.5
3 unmodified lines