mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 06:25:12 +01:00
Extend Allowed Values for HTTP Version (#3823)
This commit is contained in:
parent
a00ba52114
commit
ed3acd4b81
4 changed files with 22 additions and 11 deletions
|
@ -87,7 +87,7 @@ FieldTuple = Tuple[str, bytes, str]
|
|||
UploadFileDict = Dict[str, FieldTuple]
|
||||
"""Dictionary containing file data to be uploaded to the API."""
|
||||
|
||||
HTTPVersion = Literal["1.1", "2.0"]
|
||||
HTTPVersion = Literal["1.1", "2.0", "2"]
|
||||
"""Allowed HTTP versions.
|
||||
|
||||
.. versionadded:: 20.4"""
|
||||
|
|
|
@ -592,8 +592,11 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
|
|||
Reset the default version to 1.1.
|
||||
|
||||
Args:
|
||||
http_version (:obj:`str`): Pass ``"2"`` if you'd like to use HTTP/2 for making
|
||||
requests to Telegram. Defaults to ``"1.1"``, in which case HTTP/1.1 is used.
|
||||
http_version (:obj:`str`): Pass ``"2"`` or ``"2.0"`` if you'd like to use HTTP/2 for
|
||||
making requests to Telegram. Defaults to ``"1.1"``, in which case HTTP/1.1 is used.
|
||||
|
||||
.. versionchanged:: NEXT.VERSION
|
||||
Accept ``"2"`` as a valid value.
|
||||
|
||||
Returns:
|
||||
:class:`ApplicationBuilder`: The same builder with the updated argument.
|
||||
|
@ -751,8 +754,12 @@ class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
|
|||
Reset the default version to 1.1.
|
||||
|
||||
Args:
|
||||
get_updates_http_version (:obj:`str`): Pass ``"2"`` if you'd like to use HTTP/2 for
|
||||
making requests to Telegram. Defaults to ``"1.1"``, in which case HTTP/1.1 is used.
|
||||
get_updates_http_version (:obj:`str`): Pass ``"2"`` or ``"2.0"`` if you'd like to use
|
||||
HTTP/2 for making requests to Telegram. Defaults to ``"1.1"``, in which case
|
||||
HTTP/1.1 is used.
|
||||
|
||||
.. versionchanged:: NEXT.VERSION
|
||||
Accept ``"2"`` as a valid value.
|
||||
|
||||
Returns:
|
||||
:class:`ApplicationBuilder`: The same builder with the updated argument.
|
||||
|
|
|
@ -82,13 +82,16 @@ class HTTPXRequest(BaseRequest):
|
|||
With a finite pool timeout, you must expect :exc:`telegram.error.TimedOut`
|
||||
exceptions to be thrown when more requests are made simultaneously than there are
|
||||
connections in the connection pool!
|
||||
http_version (:obj:`str`, optional): If ``"2"``, HTTP/2 will be used instead of HTTP/1.1.
|
||||
Defaults to ``"1.1"``.
|
||||
http_version (:obj:`str`, optional): If ``"2"`` or ``"2.0"``, HTTP/2 will be used instead
|
||||
of HTTP/1.1. Defaults to ``"1.1"``.
|
||||
|
||||
.. versionadded:: 20.1
|
||||
.. versionchanged:: 20.2
|
||||
Reset the default version to 1.1.
|
||||
|
||||
.. versionchanged:: NEXT.VERSION
|
||||
Accept ``"2"`` as a valid value.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("_client", "_client_kwargs", "_http_version")
|
||||
|
@ -115,8 +118,8 @@ class HTTPXRequest(BaseRequest):
|
|||
max_keepalive_connections=connection_pool_size,
|
||||
)
|
||||
|
||||
if http_version not in ("1.1", "2"):
|
||||
raise ValueError("`http_version` must be either '1.1' or '2'.")
|
||||
if http_version not in ("1.1", "2", "2.0"):
|
||||
raise ValueError("`http_version` must be either '1.1', '2.0' or '2'.")
|
||||
|
||||
http1 = http_version == "1.1"
|
||||
|
||||
|
|
|
@ -85,8 +85,9 @@ class TestNoSocksHTTP2WithoutRequest:
|
|||
|
||||
@pytest.mark.skipif(not TEST_WITH_OPT_DEPS, reason="Optional dependencies not installed")
|
||||
class TestHTTP2WithRequest:
|
||||
async def test_http_2_response(self):
|
||||
httpx_request = HTTPXRequest(http_version="2")
|
||||
@pytest.mark.parametrize("http_version", ["2", "2.0"])
|
||||
async def test_http_2_response(self, http_version):
|
||||
httpx_request = HTTPXRequest(http_version=http_version)
|
||||
async with httpx_request:
|
||||
resp = await httpx_request._client.request(
|
||||
url="https://python-telegram-bot.org",
|
||||
|
|
Loading…
Reference in a new issue