Skip to content

Conversation

@karpetrosyan
Copy link
Contributor

@karpetrosyan karpetrosyan commented Oct 6, 2023

Summary

HTTPX supports proxies and mounts arguments, which are not the same, but mounts can simply replace proxies for complex routing, which is not always used.

So for simplicity, this PR deprecates proxies and adds proxy argument.
You can still use proxies, but it will warn you that it is deprecated and that you should use the new API.

Use...

  • proxy if you want to use a proxy server for all your requests.
  • mounts if you want to use a proxy server for requests matching the URL pattern you specified.

Proxy

import httpx

# instead of 
# httpx.Client(proxies="http://127.0.0.1:80")
# and
# httpx.Client(proxies={"all://": "http://127.0.0.1:80"})
# do ...
client = httpx.Client(proxy="http://127.0.0.1:80")

Mounts

import httpx

# instead of
# client = httpx.Client(
#    proxies={"http://": "http://127.0.0.1:80", "https://": "https://127.0.0.1:443"}
# )
# do ...
client = httpx.Client(
    mounts={
        "http://": httpx.HTTPTransport(proxy="http://127.0.0.1:80"),
        "https://": httpx.HTTPTransport(proxy="https://127.0.0.1:443"),
    }
)

@karpetrosyan karpetrosyan added the api change PRs that contain breaking public API changes label Oct 6, 2023
@karpetrosyan
Copy link
Contributor Author

@encode/maintainers If we want to switch to this API, I can work on the documentation.

I don't want to rush API changes, but if we believe the proxies API is not persistent, we should probably change it before 1.0.0, for example, deprecate it in the next release and remove it in 1.0.0.

@lovelydinosaur
Copy link
Contributor

Yep seems like a clear API rationalisation to me, I'd be happy for us to make this switch for 1.0.

It woud probably also make sense for us to widen the available types for the proxy argument on httpx.HTTPTransport, so that the mount style is kept fairly simple...

client = httpx.Client(
    mounts={
        "http://": httpx.HTTPTransport(proxy="http://127.0.0.1:80"),
        "https://": httpx.HTTPTransport(proxy="https://127.0.0.1:443"),
    }
)

@karpetrosyan karpetrosyan marked this pull request as draft October 10, 2023 13:54
lovelydinosaur and others added 2 commits October 11, 2023 09:35
Co-authored-by: T-256 <132141463+T-256@users.noreply.github.com>
Co-authored-by: T-256 <132141463+T-256@users.noreply.github.com>
@karpetrosyan
Copy link
Contributor Author

karpetrosyan commented Oct 11, 2023

Okay, so I can say that we should carefully consider how we will document this.
At this time, all of the routing staff described in the HTTP Proxies section do not make sense with the current implementation.
I propose that we change the documentation in a separate PR, and that we also document this feature there.

That new PR should answer this question:

  • What structure do we want for the HTTPX 1.0 documentation?
  • How do we want to document the deprecated things?
  • Do we want to describe custom transports more detailed? & Move the routing section into it.

I also want that PR will make HTTPX documentation more user-friendly and add some Mkdocs material features that can possibly make the documentation more readable and pleasant.

@lovelydinosaur
Copy link
Contributor

Excellent questions, though quite wide ranging.

For the purposes of this pull request I'd suggest that...

  • The proxy routing docs move into the "mounting transports" section.
  • Deprecations are mentioned in the CHANGELOG.

@karpetrosyan karpetrosyan marked this pull request as ready for review October 12, 2023 07:29
Copy link
Contributor

@lovelydinosaur lovelydinosaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

The command-line client also currently uses --proxies - I'd suggest we change that also.

For example here...

"--proxies [cyan]URL",

as well as in a few other places in that module.

@karpetrosyan
Copy link
Contributor Author

Do we want to keep the proxies argument in the cli app?
The migration is so easy; the user should just change the proxies word to proxy, so we can entirely remove it.

@lovelydinosaur
Copy link
Contributor

the user should just change the proxies word to proxy

I'm happy with making that change, yes.

karpetrosyan and others added 4 commits December 11, 2023 16:11
Co-authored-by: Tom Christie <tom@tomchristie.com>
Co-authored-by: Tom Christie <tom@tomchristie.com>
Co-authored-by: Tom Christie <tom@tomchristie.com>
@lovelydinosaur
Copy link
Contributor

Looking great. Let's...

  • Update the description to indicate that proxies=... will continue to work at this point in time, but will issue a warning. (That's correct yeah?)
  • Should we drop proxies from the docstrings at this point, given that it's deprecated. Perhaps code comments alongside proxies=... indicating "# Deprecated. Remains functional, but will raise a warning if used."`?

@karpetrosyan
Copy link
Contributor Author

That's correct yeah?

Yes

Should we drop proxies from the docstrings at this point, given that it's deprecated. Perhaps code comments alongside proxies=... indicating "# Deprecated. Remains functional, but will raise a warning if used."`?

Is there a reason we need to get rid of docstring? I thought we were going to remove everything related to proxies with the major release.
We can look at how other encode projects deprecate things, but I don't think it's necessary.

@karpetrosyan karpetrosyan merged commit f8981f3 into encode:master Dec 11, 2023
@karpetrosyan karpetrosyan mentioned this pull request Dec 18, 2023
@lovelydinosaur lovelydinosaur mentioned this pull request Jan 8, 2024
markotoplak added a commit to markotoplak/orange3 that referenced this pull request Nov 29, 2024
@agahen agahen mentioned this pull request Dec 5, 2024
samclearman pushed a commit to titanmsp/httpx that referenced this pull request Apr 26, 2025
* Add the proxy parameter and deprecate proxies

* Make the Client.proxy and HTTPTransport.proxy types the same

* Update httpx/_transports/default.py

Co-authored-by: T-256 <132141463+T-256@users.noreply.github.com>

* Update httpx/_transports/default.py

Co-authored-by: T-256 <132141463+T-256@users.noreply.github.com>

* Drop unneeded noqa

* Changelog

* update documentation

* Allow None in mounts

* typos

* Update httpx/_types.py

* Changes proxies to proxy in CLI app

* Add proxy to request function

* Update CHANGELOG.md

Co-authored-by: Tom Christie <tom@tomchristie.com>

* Update docs/troubleshooting.md

Co-authored-by: Tom Christie <tom@tomchristie.com>

* Update docs/troubleshooting.md

Co-authored-by: Tom Christie <tom@tomchristie.com>

* Lint

---------

Co-authored-by: Tom Christie <tom@tomchristie.com>
Co-authored-by: T-256 <132141463+T-256@users.noreply.github.com>
Zocker1999NET added a commit to Zocker1999NET/youtube-search-python that referenced this pull request May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change PRs that contain breaking public API changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants