Skip to content
Myr

Clean up '_dispatcher_for_request' into 'dispatcher_for_url' (#561)

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

authored by Tom Christie · committed by GitHub · parent 44ad295 · Browse files · 2 files+10 added−11 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+10 added−11 removed

  • tests:+1 added−2 removed
  • other:+9 added−9 removed

2 files+10 added−11 removed

modified:httpx/client.py+9 added-9 removed
533 unmodified lines
534 """535 Sends a single request, without handling any redirections.536 """537538 dispatcher = self._dispatcher_for_request(request, self.proxies)538 dispatcher = self.dispatcher_for_url(request.url)539540 try:541 with ElapsedTimer() as timer:542 response = await dispatcher.send(
16 unmodified lines
559 logger.debug(f'HTTP Request: {request.method} {request.url} "{response_line}"')560561 return response562563 def _dispatcher_for_request(564 self, request: Request, proxies: typing.Dict[str, Dispatcher]565 ) -> Dispatcher:566 """Gets the Dispatcher instance that should be used for a given Request"""567 if proxies:568 url = request.url563 def dispatcher_for_url(self, url: URL) -> Dispatcher:564 """565 Returns the Dispatcher instance that should be used for a given URL.566 This will either be the standard connection pool, or a proxy.567 """568 if self.proxies:569 is_default_port = (url.scheme == "http" and url.port == 80) or (570 url.scheme == "https" and url.port == 443571 )572 hostname = f"{url.host}:{url.port}"
5 unmodified lines
578 url.scheme,579 "all",580 )581 for proxy_key in proxy_keys:582 if proxy_key and proxy_key in proxies:583 dispatcher = proxies[proxy_key]582 if proxy_key and proxy_key in self.proxies:583 dispatcher = self.proxies[proxy_key]584 return dispatcher585586 return self.dispatch587
283 unmodified lines
modified:tests/client/test_proxies.py+1 added-2 removed
100 unmodified lines
101 ],102)103def test_dispatcher_for_request(url, proxies, expected):104 client = httpx.Client(proxies=proxies)105 request = httpx.Request("GET", url)106 dispatcher = client._dispatcher_for_request(request, client.proxies)105 dispatcher = client.dispatcher_for_url(httpx.URL(url))106107 if expected is None:108 assert isinstance(dispatcher, httpx.ConnectionPool)109 assert dispatcher is client.dispatch
8 unmodified lines