This repository was archived by the owner on May 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 387
feat: add proxy support to ClobClient initialization #315
Open
zyaiire
wants to merge
2
commits into
Polymarket:main
Choose a base branch
from
zyaiire:feat/309-add-proxy-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from unittest import TestCase | ||
| from unittest.mock import patch, MagicMock | ||
|
|
||
| from py_clob_client.http_helpers.helpers import set_proxy | ||
|
|
||
|
|
||
| class TestProxy(TestCase): | ||
| @patch("py_clob_client.http_helpers.helpers.httpx.Client") | ||
| def test_set_proxy_creates_client_with_proxy(self, mock_client_cls): | ||
| """set_proxy should create a new httpx.Client with the proxy param.""" | ||
| old_client = MagicMock() | ||
| mock_client_cls.side_effect = [old_client, MagicMock()] | ||
|
|
||
| set_proxy("http://localhost:8080") | ||
|
|
||
| mock_client_cls.assert_called_with(http2=True, proxy="http://localhost:8080") | ||
| old_client.close.assert_called_once() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests assert on wrong mock object for closeMedium Severity The module-level Additional Locations (2) |
||
|
|
||
| @patch("py_clob_client.http_helpers.helpers.httpx.Client") | ||
| def test_set_proxy_none_creates_client_without_proxy(self, mock_client_cls): | ||
| """set_proxy(None) should create a client without the proxy param.""" | ||
| old_client = MagicMock() | ||
| mock_client_cls.side_effect = [old_client, MagicMock()] | ||
|
|
||
| set_proxy(None) | ||
|
|
||
| mock_client_cls.assert_called_with(http2=True) | ||
| old_client.close.assert_called_once() | ||
|
|
||
| @patch("py_clob_client.http_helpers.helpers.httpx.Client") | ||
| def test_set_proxy_empty_string_creates_client_without_proxy(self, mock_client_cls): | ||
| """set_proxy('') should create a client without the proxy param.""" | ||
| old_client = MagicMock() | ||
| mock_client_cls.side_effect = [old_client, MagicMock()] | ||
|
|
||
| set_proxy("") | ||
|
|
||
| mock_client_cls.assert_called_with(http2=True) | ||
| old_client.close.assert_called_once() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unconditional
set_proxycall destroys shared HTTP clientHigh Severity
set_proxy(proxy)is called unconditionally in__init__, even whenproxyisNone(the default). Sinceset_proxyalways closes the existing module-level_http_clientand creates a new one, everyClobClientinstantiation — even without a proxy — destroys the shared HTTP client, dropping all keep-alive connections and HTTP/2 state. This is a regression for all existing users and can break in-flight requests if multipleClobClientinstances coexist.Additional Locations (1)
py_clob_client/http_helpers/helpers.py#L21-L35