Repository: pulp/pulpcore

Issue:
Aiohttp rewrites redirect URLs, breaking some requests to Amazon Web servers, unless you tell it not to.  Let's do that.
**Version**
All

**Describe the bug**
Unless you tell it otherwise, aiotthp can potentially alter the redirect URL it receives from a remote webserver.  This is legal as is the encoding of the new URL, but some web servers are temperamental and expect URL to be encoded in a particular way.

We ought to turn this off by default.

https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession.requote_redirect_url

**To Reproduce**

```
In [1]: import aiohttp
   ...: import asyncio
   ...: 
   ...: async def main():
   ...: 
   ...:    async with aiohttp.ClientSession() as session:
   ...:       async with session.get('https://releases.jfrog.io/artifactory/artifactory-pro-rpms/repodata/8c87521e43dbed223c90
   ...: e23922c0c4bbe7159112-primary.xml.gz') as response:
   ...: 
   ...:             print("Status:", response.status)
   ...:             print("Content-type:", response.headers['content-type'])
   ...: 
   ...:             html = await response.text()
   ...:             print("Body:", html)
   ...: 
   ...: loop = asyncio.get_event_loop()
   ...: loop.run_until_complete(main())
<ipython-input-1-8662e4a98f2f>:15: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
Status: 403
Content-type: text/xml
Body: <?xml version="1.0" encoding="UTF-8"?><Error><Code>AccessDenied</Code><Message>Access denied</Message></Error>

In [2]: import aiohttp
   ...: import asyncio
   ...: 
   ...: async def main():
   ...: 
   ...:    async with aiohttp.ClientSession(requote_redirect_url=False) as session:
   ...:       async with session.get('https://releases.jfrog.io/artifactory/artifactory-pro-rpms/repodata/8c87521e43dbed223c90
   ...: e23922c0c4bbe7159112-primary.xml.gz') as response:
   ...: 
   ...:             print("Status:", response.status)
   ...:             print("Content-type:", response.headers['content-type'])
   ...: 
   ...:             html = await response.text()
   ...:             print("Body:", html)
   ...: 
   ...: loop = asyncio.get_event_loop()
   ...: loop.run_until_complete(main())
<ipython-input-2-32fd9ff02673>:15: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
Status: 200
Content-type: application/x-gzip

```


**Additional context**
https://bugzilla.redhat.com/show_bug.cgi?id=2104498



Discussion:

Resolving patch:
diff --git a/pulpcore/download/factory.py b/pulpcore/download/factory.py
--- a/pulpcore/download/factory.py
+++ b/pulpcore/download/factory.py
@@ -142,7 +142,9 @@ def _make_aiohttp_session_from_remote(self):
         timeout = aiohttp.ClientTimeout(
             total=total, sock_connect=sock_connect, sock_read=sock_read, connect=connect
         )
-        return aiohttp.ClientSession(connector=conn, timeout=timeout, headers=headers)
+        return aiohttp.ClientSession(
+            connector=conn, timeout=timeout, headers=headers, requote_redirect_url=False
+        )
 
     def build(self, url, **kwargs):
         """
diff --git a/pulpcore/download/http.py b/pulpcore/download/http.py
--- a/pulpcore/download/http.py
+++ b/pulpcore/download/http.py
@@ -177,7 +177,9 @@ def __init__(
         else:
             timeout = aiohttp.ClientTimeout(total=None, sock_connect=600, sock_read=600)
             conn = aiohttp.TCPConnector({"force_close": True})
-            self.session = aiohttp.ClientSession(connector=conn, timeout=timeout, headers=headers)
+            self.session = aiohttp.ClientSession(
+                connector=conn, timeout=timeout, headers=headers, requote_redirect_url=False
+            )
             self._close_session_on_finalize = True
         self.auth = auth
         self.proxy = proxy


Test patch: