Skip to content

Add OpenConnection base class - #616

Merged
florimondmanca merged 2 commits into
masterfrom
refactor/open-connection
Dec 9, 2019
Merged

florimondmanca merged 2 commits into
masterfrom
refactor/open-connection

Conversation

@florimondmanca

@florimondmanca florimondmanca commented Dec 7, 2019 •

Copy link
Copy Markdown
Contributor

To progress towards resolving #496, we need to isolate the manipulation of HTTP2Connection in HTTPConnection.

This PR (inspired by #604) introduces a base OpenConnection interface that HTTP11Connection and HTTP2Connection implement, which allows HTTPConnection to hold a single open_connection object instead of one of h11_connection or h2_connection.

@florimondmanca florimondmanca added the refactor Issues and PRs related to code refactoring label Dec 7, 2019
) -> None:
if http_version == "HTTP/2":
self.h2_connection = HTTP2Connection(
self.open_connection = HTTP2Connection(

@florimondmanca florimondmanca Dec 7, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the only place where we reference HTTP2Connection in this file, so we'll be able to lazily-import it here, and fail if h2 isn't installed. 馃憤

else:
assert http_version == "HTTP/1.1"
self.h11_connection = HTTP11Connection(stream, on_release=on_release)
self.set_open_connection(http_version, socket=stream, on_release=on_release)

@florimondmanca florimondmanca Dec 7, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that we've got an outstanding stream vs socket instance here (following up #601). Wondering if should push the renaming further with .open_tcp_socket() and .open_uds_socket() on the ConcurrencyBackend interface?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems reasonable, yup.

@lovelydinosaur lovelydinosaur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems good, yup!
I think there may be a bit more we can do to avoid reaching into h11 internals from here, but we can address that seperately as needed.

else:
assert http_version == "HTTP/1.1"
self.h11_connection = HTTP11Connection(stream, on_release=on_release)
self.set_open_connection(http_version, socket=stream, on_release=on_release)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems reasonable, yup.

@florimondmanca

Copy link
Copy Markdown
Contributor Author

Thanks @tomchristie - I see what you mean about the remaining h11 internals being accessed in HTTPConnection. Seems separate from the scope of this PR so I鈥檒l merge and we can address it later!

@florimondmanca
florimondmanca merged commit e95111a into master Dec 9, 2019
@florimondmanca
florimondmanca deleted the refactor/open-connection branch December 9, 2019 10:34
Kludex referenced this pull request in pydantic/httpx2 May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Issues and PRs related to code refactoring

Development

Successfully merging this pull request may close these issues.

2 participants