Skip to content

Commit 3d6188e

Browse files
timobrembeckclaudep
authored andcommitted
Fix internal redirect checker
1 parent 5b8df42 commit 3d6188e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Unreleased
22

3+
* Fix internal redirect checker (Timo Ludwig, #180)
34
* Fix SSL status of unreachable domains (Timo Ludwig, #184)
45
* Fix URL message for internal server errorrs (Timo Ludwig, #182)
56
* Add support for Django 4.2

linkcheck/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,14 @@ def check_internal(self):
331331
self.message = 'Working internal link'
332332
self.status = True
333333
elif response.status_code < 400:
334+
initial_location = response.get('Location')
334335
redirect_type = "permanent" if response.status_code == 301 else "temporary"
335-
response = c.get(self.internal_url, follow=True)
336-
self.redirect_to, _ = response.redirect_chain[-1]
336+
with modify_settings(ALLOWED_HOSTS={'append': 'testserver'}):
337+
response = c.get(self.internal_url, follow=True)
338+
if response.redirect_chain:
339+
self.redirect_to, _ = response.redirect_chain[-1]
340+
else:
341+
self.redirect_to = initial_location
337342
self.redirect_status_code = response.status_code
338343
self.status = response.status_code < 300
339344
redirect_result = "Working" if self.status else "Broken"

0 commit comments

Comments
 (0)