-
Notifications
You must be signed in to change notification settings - Fork 125
Add HTTP3 support #829
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
Open
karpetrosyan
wants to merge
15
commits into
encode:master
Choose a base branch
from
karpetrosyan:support-http3
base: master
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
Add HTTP3 support #829
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bd31869
Support HTTP/3
karpetrosyan 383d4ce
Add http3 argument to ConnectionPool and HTTPConnection classes
karpetrosyan acce83a
Typo
karpetrosyan 0d5bf66
Fix the docstring
karpetrosyan 37cb6b4
Support both IPv4 and IPv6
karpetrosyan bcd3934
Merge branch 'master' into support-http3
karpetrosyan d21d675
Merge branch 'master' into support-http3
lovelydinosaur 306c3b4
Merge branch 'master' into support-http3
karpetrosyan 08c6271
Merge branch 'master' into support-http3
karpetrosyan c00b2f5
Merge branch 'master' into support-http3
karpetrosyan c29901b
Merge branch 'master' into support-http3
karpetrosyan 94d4c22
Merge branch 'master' into support-http3
karpetrosyan ca5e5ad
Merge branch 'master' into support-http3
karpetrosyan 120c8d1
Merge branch 'master' into support-http3
karpetrosyan 6baead4
Merge branch 'master' of https://github.com/encode/httpcore into supp…
karpetrosyan 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 |
---|---|---|
|
@@ -41,6 +41,7 @@ def __init__( | |
keepalive_expiry: Optional[float] = None, | ||
http1: bool = True, | ||
http2: bool = False, | ||
http3: bool = False, | ||
retries: int = 0, | ||
local_address: Optional[str] = None, | ||
uds: Optional[str] = None, | ||
|
@@ -52,6 +53,7 @@ def __init__( | |
self._keepalive_expiry = keepalive_expiry | ||
self._http1 = http1 | ||
self._http2 = http2 | ||
self._http3 = http3 | ||
self._retries = retries | ||
self._local_address = local_address | ||
self._uds = uds | ||
|
@@ -80,7 +82,18 @@ async def handle_async_request(self, request: Request) -> Response: | |
ssl_object is not None | ||
and ssl_object.selected_alpn_protocol() == "h2" | ||
) | ||
if http2_negotiated or (self._http2 and not self._http1): | ||
if self._http3 and not ( | ||
self._http1 or self._http2 | ||
): # pragma: no cover | ||
from .http3 import AsyncHTTP3Connection | ||
karpetrosyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
stream = await self._connect_http3(request) | ||
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. This should be doing happy eyeballs |
||
self._connection = AsyncHTTP3Connection( | ||
origin=self._origin, | ||
stream=stream, | ||
keepalive_expiry=self._keepalive_expiry, | ||
) | ||
elif http2_negotiated or (self._http2 and not self._http1): | ||
from .http2 import AsyncHTTP2Connection | ||
|
||
self._connection = AsyncHTTP2Connection( | ||
|
@@ -162,6 +175,30 @@ async def _connect(self, request: Request) -> AsyncNetworkStream: | |
async with Trace("retry", logger, request, kwargs) as trace: | ||
await self._network_backend.sleep(delay) | ||
|
||
async def _connect_http3( | ||
self, request: Request | ||
) -> AsyncNetworkStream: # pragma: nocover | ||
retries_left = self._retries | ||
delays = exponential_backoff(factor=RETRIES_BACKOFF_FACTOR) | ||
|
||
while True: | ||
try: | ||
kwargs = { | ||
"host": self._origin.host.decode("ascii"), | ||
"port": self._origin.port, | ||
} | ||
async with Trace("connect_udp", logger, request, kwargs) as trace: | ||
stream = await self._network_backend.connect_udp(**kwargs) # type: ignore | ||
trace.return_value = stream | ||
return stream | ||
except (ConnectError, ConnectTimeout): | ||
if retries_left <= 0: | ||
raise | ||
retries_left -= 1 | ||
delay = next(delays) | ||
async with Trace("retry", logger, request, kwargs) as trace: | ||
await self._network_backend.sleep(delay) | ||
|
||
def can_handle_request(self, origin: Origin) -> bool: | ||
return origin == self._origin | ||
|
||
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.