Adding Transport API support for CONNECT
/Upgrade
requests.
#1650
Unanswered
tomchristie
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Opening this discussion to give some visibility onto my thought processes on supporting
CONNECT
/Upgrade
requests & how it ties in with the low-level Transport API.Let's start this off with a recap on sending a request directly using the low-level API.
example.py
Shell:
Okay, so next observation here is that one of the sharper things that we'd like to be able to do with
httpx
is support HTTP requests that use theCONNECT
method, or theUpgrade
header. See #1150In both of those two cases, the initial request starts off being negotiated using HTTP, and then switches the mode of connection into a raw read/write stream. This is an important bit of functionality, because it enables use-cases such as WebSockets, which are initially negotiated over HTTP. The sort of thing we'd like to be able to do here (at a low-level) is this kind of thing:
One of the neat things we'll be able to provide for with
HTTPX
here is to ensure that theconnection
that's returned here is either reading/writing directly to the socket (for HTTP/1.1) or onto a single HTTP stream (for HTTP/2), with either case being handled transparently to the end-user.Now, something that'd be super wonderful would be if we were able to fully express proxy requests using the Transport API. That'd just really round out the completeness of the API.
We can already support proxy forwarding, because our
url
format allows the target to be fully specified, so eg to connect to an HTTP URL we can currently do this:But making a proxy request to an HTTPS URL, requires a CONNECT request.
We'd like to be able to do something like this:
What hadn't occurred to me, until I started thinking about proxy CONNECT requests, is that a
"connection"
extension makes sense both as a response extension, and as a request extension. It'd also be a really neatly powerful bit of kit for us to have, since it provides a window into "read and write the bytes to this thing".Some slight glossing over here. The Transport API doesn't return context managers. Just a plain-ol-tuple. But trying to get the idea across for now.
Beta Was this translation helpful? Give feedback.
All reactions