diff --git a/CHANGES/2278.removal b/CHANGES/2278.removal new file mode 100644 index 00000000000..9e5a9983c37 --- /dev/null +++ b/CHANGES/2278.removal @@ -0,0 +1 @@ +Deprecate modification of ``session.requote_redirect_url`` diff --git a/aiohttp/client.py b/aiohttp/client.py index 06981b31404..fd2b71eedd7 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -98,8 +98,6 @@ class ClientSession: _source_traceback = None _connector = None - requote_redirect_url = True - def __init__(self, *, connector: Optional[BaseConnector]=None, loop: Optional[asyncio.AbstractEventLoop]=None, cookies: Optional[LooseCookies]=None, @@ -119,6 +117,7 @@ def __init__(self, *, connector: Optional[BaseConnector]=None, timeout: Union[object, ClientTimeout]=sentinel, auto_decompress: bool=True, trust_env: bool=False, + requote_redirect_url: bool=True, trace_configs: Optional[List[TraceConfig]]=None) -> None: if loop is None: @@ -171,6 +170,7 @@ def __init__(self, *, connector: Optional[BaseConnector]=None, self._raise_for_status = raise_for_status self._auto_decompress = auto_decompress self._trust_env = trust_env + self._requote_redirect_url = requote_redirect_url # Convert to list of tuples if headers: @@ -468,7 +468,7 @@ async def _request( try: r_url = URL( - r_url, encoded=not self.requote_redirect_url) + r_url, encoded=not self._requote_redirect_url) except ValueError: raise InvalidURL(r_url) @@ -841,6 +841,20 @@ def version(self) -> Tuple[int, int]: """The session HTTP protocol version.""" return self._version + @property + def requote_redirect_url(self) -> bool: + """Do URL requoting on redirection handling.""" + return self._requote_redirect_url + + @requote_redirect_url.setter + def requote_redirect_url(self, val: bool) -> None: + """Do URL requoting on redirection handling.""" + warnings.warn("session.requote_redirect_url modification " + "is deprecated #2778", + DeprecationWarning, + stacklevel=2) + self._requote_redirect_url = val + @property def loop(self) -> asyncio.AbstractEventLoop: """Session's loop.""" diff --git a/docs/client_reference.rst b/docs/client_reference.rst index fd1bf2c3604..cfa8d7b11be 100644 --- a/docs/client_reference.rst +++ b/docs/client_reference.rst @@ -48,7 +48,10 @@ The client session supports the context manager protocol for self closing. timeout=sentinel, \ raise_for_status=False, \ connector_owner=True, \ - auto_decompress=True, proxies=None) + auto_decompress=True, \ + requote_redirect_url=False, \ + trust_env=False, \ + trace_configs=None) The class for creating client sessions and making requests. @@ -176,6 +179,17 @@ The client session supports the context manager protocol for self closing. Added support for ``~/.netrc`` file. + :param bool requote_redirect_url: Apply *URL requoting* for redirection URLs if + automatic redirection is enabled (``True`` by + default). + + .. versionadded:: 3.5 + + :param trace_configs: A list of :class:`TraceConfig` instances used for client + tracing. ``None`` (default) is used for request tracing + disabling. See :ref:`aiohttp-client-tracing-reference` for + more information. + .. attribute:: closed ``True`` if the session has been closed, ``False`` otherwise. @@ -207,6 +221,10 @@ The client session supports the context manager protocol for self closing. .. note:: This parameter affects all subsequent requests. + .. deprecated:: 3.5 + + The attribute modification is deprecated. + .. attribute:: loop A loop instance used for session creation. diff --git a/tests/test_client_session.py b/tests/test_client_session.py index 3934aab308f..6c48728060f 100644 --- a/tests/test_client_session.py +++ b/tests/test_client_session.py @@ -687,3 +687,21 @@ async def test_client_session_timeout_args(loop) -> None: ClientSession(loop=loop, timeout=client.ClientTimeout(total=10 * 60), conn_timeout=30 * 60) + + +async def test_requote_redirect_url_default() -> None: + session = ClientSession() + assert session.requote_redirect_url + + +async def test_requote_redirect_url_default_disable() -> None: + session = ClientSession(requote_redirect_url=False) + assert not session.requote_redirect_url + + +async def test_requote_redirect_setter() -> None: + session = ClientSession() + assert session.requote_redirect_url + with pytest.warns(DeprecationWarning): + session.requote_redirect_url = False + assert not session.requote_redirect_url