Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes ability to specify custom headers on a Remote
The Remotes APIs accepts a list of headers to be sent with each request during sync. However, the headers were not being properly passed to aiohttp. This patch fixes how the headers are passed to aiohttp. This patch also ensures that any User-Agent headers configured on a remote are appended to the User-Agent string generated by pulp. fixes: #8689 https://pulp.plan.io/issues/8689
- Loading branch information
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed ability to specify custom headers on a Remote. |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.test import TestCase | ||
|
||
from pulpcore.download.factory import DownloaderFactory, user_agent | ||
from pulpcore.plugin.models import Remote | ||
|
||
|
||
class DownloaderFactoryHeadersTestCase(TestCase): | ||
def test_user_agent_header(self): | ||
remote = Remote.objects.create(url="http://example.org/", name="foo") | ||
factory = DownloaderFactory(remote) | ||
downloader = factory.build(remote.url) | ||
default_user_agent = user_agent() | ||
self.assertEqual(downloader.session.headers["User-Agent"], default_user_agent) | ||
remote.delete() | ||
|
||
def test_custom_user_agent_header(self): | ||
remote = Remote.objects.create( | ||
url="http://example.org/", headers=[{"User-Agent": "foo"}], name="foo" | ||
) | ||
factory = DownloaderFactory(remote) | ||
downloader = factory.build(remote.url) | ||
default_user_agent = user_agent() | ||
expected_user_agent = f"{default_user_agent}, foo" | ||
self.assertEqual(downloader.session.headers["User-Agent"], expected_user_agent) | ||
remote.delete() | ||
|
||
def test_custom_headers(self): | ||
remote = Remote.objects.create( | ||
url="http://example.org/", headers=[{"Connection": "keep-alive"}], name="foo" | ||
) | ||
factory = DownloaderFactory(remote) | ||
downloader = factory.build(remote.url) | ||
self.assertEqual(downloader.session.headers["Connection"], "keep-alive") |