Skip to content

Commit

Permalink
Fix URL encoding issue in HttpDownloader to handle special characters
Browse files Browse the repository at this point in the history
closes pulp#5686
  • Loading branch information
hstct committed Sep 17, 2024
1 parent 0cd8dc1 commit 527d9c8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pulpcore/download/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import aiohttp
import asyncio
import backoff
import urllib.parse

from .base import BaseDownloader, DownloadResult
from pulpcore.exceptions import (
Expand Down Expand Up @@ -49,6 +50,14 @@ def http_giveup_handler(exc):
return False


def encode_url(url):
"""Helper function to encode only the path part of the URL."""
parsed_url = urllib.parse.urlparse(url)
encoded_path = urllib.parse.quote(parsed_url.path)
encoded_url = parsed_url._replace(path=encoded_path).geturl()
return encoded_url


class HttpDownloader(BaseDownloader):
"""
An HTTP/HTTPS Downloader built on `aiohttp`.
Expand Down Expand Up @@ -284,8 +293,9 @@ async def _run(self, extra_data=None):
"""
if self.download_throttler:
await self.download_throttler.acquire()
encoded_url = encode_url(self.url)
async with self.session.get(
self.url, proxy=self.proxy, proxy_auth=self.proxy_auth, auth=self.auth
encoded_url, proxy=self.proxy, proxy_auth=self.proxy_auth, auth=self.auth
) as response:
self.raise_for_status(response)
to_return = await self._handle_response(response)
Expand Down

0 comments on commit 527d9c8

Please sign in to comment.