Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shouldn env_proxy affect after proxy that provided by users from code #10025

Open
1 task done
NewUserHa opened this issue Nov 21, 2024 · 3 comments
Open
1 task done

Comments

@NewUserHa
Copy link
Contributor

NewUserHa commented Nov 21, 2024

Is your feature request related to a problem?

aiohttp/aiohttp/client.py

Lines 502 to 507 in e79b2d5

if proxy is None:
proxy = self._default_proxy
if proxy_auth is None:
proxy_auth = self._default_proxy_auth

aiohttp/aiohttp/client.py

Lines 609 to 617 in e79b2d5

if proxy is not None:
proxy = URL(proxy)
elif self._trust_env:
with suppress(LookupError):
proxy, proxy_auth = get_env_proxy_for_url(url)
req = self._request_class(
method,

currently, the async def _request(...)

  • uses proxy from env first than from code
  • it at the same time causes calling get env proxy from env and registry in each request(aka _request()) call.

Describe the solution you'd like

keep env proxy in session, and use after code proxy that provided by users
also should throw error for socks5 proxy since aiohttp does not work with socks5 currently

Describe alternatives you've considered

N/A

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@asvetlov
Copy link
Member

Sorry, I re-read the message several times and still cannot figure out what is the question.

@NewUserHa
Copy link
Contributor Author

NewUserHa commented Nov 22, 2024

  • when both proxy settings in environment variable and ClientSession(proxy='...') exist, the async def _request(...) will use the former. see line 614 and 504, the _default_proxy in 504 is read from latter.
  • also here get_env_proxy_for_url(url) will read env and registry each time _request(...) is called, however the env proxy should be kept in session rather than lookup for each request
  • aiohttp should explicitly throw error for socks5 proxy if provided, since aiohttp only support HTTP proxy does not support socks5 proxy at all

@asvetlov
Copy link
Member

Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants