Skip to content

Commit

Permalink
🐛 fix resolving lazy responses when emitted through a SOCKS, HTTP or …
Browse files Browse the repository at this point in the history
…HTTPS proxy (#178)

Close #170
  • Loading branch information
Ousret authored Nov 13, 2024
1 parent 3e31774 commit d14091e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release History
===============

3.10.3 (2024-11-13)
------------------

**Fixed**
- Resolving lazy responses when emitted through a SOCKS, HTTP or HTTPS proxy. (#170)

3.10.2 (2024-10-25)
------------------

Expand Down
4 changes: 2 additions & 2 deletions src/niquests/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
__url__: str = "https://niquests.readthedocs.io"

__version__: str
__version__ = "3.10.2"
__version__ = "3.10.3"

__build__: int = 0x031002
__build__: int = 0x031003
__author__: str = "Kenneth Reitz"
__author_email__: str = "[email protected]"
__license__: str = "Apache-2.0"
Expand Down
46 changes: 34 additions & 12 deletions src/niquests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,11 @@ def gather(self, *responses: Response, max_fetch: int | None = None) -> None:
if not self._promises:
return

mgrs: list[PoolManager | ProxyManager] = [
self.poolmanager,
*[pm for pm in self.proxy_manager.values()],
]

# Either we did not have a list of promises to fulfill...
if not responses:
while True:
Expand All @@ -1233,7 +1238,10 @@ def gather(self, *responses: Response, max_fetch: int | None = None) -> None:

if low_resp is None:
try:
low_resp = self.poolmanager.get_response()
for src in mgrs:
low_resp = src.get_response()
if low_resp is not None:
break
except (ProtocolError, OSError) as err:
raise ConnectionError(err)

Expand Down Expand Up @@ -1308,11 +1316,14 @@ def gather(self, *responses: Response, max_fetch: int | None = None) -> None:
continue

try:
low_resp = self.poolmanager.get_response(
promise=response._promise
)
except ValueError:
low_resp = None
for src in mgrs:
try:
low_resp = src.get_response(promise=response._promise)
except ValueError:
low_resp = None

if low_resp is not None:
break
except (ProtocolError, OSError) as err:
raise ConnectionError(err)

Expand Down Expand Up @@ -2306,6 +2317,11 @@ async def gather(
if not self._promises:
return

mgrs: list[AsyncPoolManager | AsyncProxyManager] = [
self.poolmanager,
*[pm for pm in self.proxy_manager.values()],
]

# Either we did not have a list of promises to fulfill...
if not responses:
while True:
Expand All @@ -2327,7 +2343,10 @@ async def gather(

if low_resp is None:
try:
low_resp = await self.poolmanager.get_response()
for src in mgrs:
low_resp = await src.get_response()
if low_resp is not None:
break
except (ProtocolError, OSError) as err:
raise ConnectionError(err)

Expand Down Expand Up @@ -2402,11 +2421,14 @@ async def gather(
continue

try:
low_resp = await self.poolmanager.get_response(
promise=response._promise
)
except ValueError:
low_resp = None
for src in mgrs:
try:
low_resp = await src.get_response(promise=response._promise)
except ValueError:
low_resp = None

if low_resp is not None:
break
except (ProtocolError, OSError) as err:
raise ConnectionError(err)

Expand Down

0 comments on commit d14091e

Please sign in to comment.