From 5324f7db72d813dd2fbc534676a6f97de133aa7b Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Wed, 15 Sep 2021 11:33:25 -0400 Subject: [PATCH] Change HTTPResponse.links to return empty list when Link header is not present --- docs/history.rst | 4 ++++ sprockets/mixins/http/__init__.py | 4 ++-- tests.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/history.rst b/docs/history.rst index 5961d56..f2a776f 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -1,6 +1,10 @@ Version History =============== +Next +---- +- Change ``HTTPResponse.links`` to return empty list when ``Link`` header is not present + `2.4.1`_ Nov 30 2020 -------------------- - Make request retry timeout configurable diff --git a/sprockets/mixins/http/__init__.py b/sprockets/mixins/http/__init__.py index 1548151..bec12d8 100644 --- a/sprockets/mixins/http/__init__.py +++ b/sprockets/mixins/http/__init__.py @@ -152,13 +152,13 @@ class HTTPResponse: """ if not self._responses: return None + links = [] if 'Link' in self._responses[-1].headers: - links = [] for l in headers.parse_link(self._responses[-1].headers['Link']): link = {'target': l.target} link.update({k: v for (k, v) in l.parameters}) links.append(link) - return links + return links @property def ok(self): diff --git a/tests.py b/tests.py index a8d0bce..f6906dd 100644 --- a/tests.py +++ b/tests.py @@ -258,7 +258,7 @@ class MixinTestCase(testing.AsyncHTTPTestCase): 'foo': ['bar'], 'status_code': ['200'] }) - self.assertIsNone(response.links) + self.assertEqual(response.links, []) @testing.gen_test def test_post(self):