Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,29 @@ Whether links with broken hash anchors should be marked as valid.
Disable this if you want that links to anchors which are not contained in the link target's HTML source are marked as invalid.


LINKCHECK_PROXIES
~~~~~~~~~~~~~~~~~

Default: `{}`

Allows you to make your `check_external` requests via a proxy. Expects a dictionary, e.g.:

```
LINKCHECK_PROXIES = {
"http": "http://...",
"https": "https://...",
}
```


LINKCHECK_TRUST_PROXY_SSL
~~~~~~~~~~~~~~~~~~~~~~~~~

Default: `False`

If you are making your requests via a proxy, you can use this setting to turn off SSL verification for the proxy.


django-filebrowser integration
------------------------------

Expand Down
2 changes: 2 additions & 0 deletions linkcheck/linkcheck_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@
SITE_DOMAINS = getattr(settings, 'LINKCHECK_SITE_DOMAINS', [])
DISABLE_LISTENERS = getattr(settings, 'LINKCHECK_DISABLE_LISTENERS', False)
TOLERATE_BROKEN_ANCHOR = getattr(settings, 'LINKCHECK_TOLERATE_BROKEN_ANCHOR', True)
PROXIES = getattr(settings, 'LINKCHECK_PROXIES', {})
TRUST_PROXY_SSL = getattr(settings, 'LINKCHECK_TRUST_PROXY_SSL', False)
6 changes: 6 additions & 0 deletions linkcheck/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
LINKCHECK_CONNECTION_ATTEMPT_TIMEOUT,
MAX_URL_LENGTH,
MEDIA_PREFIX,
PROXIES,
SITE_DOMAINS,
TOLERATE_BROKEN_ANCHOR,
TRUST_PROXY_SSL,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -386,6 +388,10 @@ def check_external(self, external_recheck_interval=EXTERNAL_RECHECK_INTERVAL):
"timeout": LINKCHECK_CONNECTION_ATTEMPT_TIMEOUT,
"verify": True,
}
if PROXIES:
request_params["verify"] = not TRUST_PROXY_SSL
request_params["proxies"] = PROXIES

try:
try:
# At first try a HEAD request
Expand Down
19 changes: 19 additions & 0 deletions linkcheck/tests/test_linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,25 @@ def test_external_check_blocked_user_agent_blocked_head(self):
self.assertEqual(uv.redirect_to, '')
self.assertEqual(uv.type, 'external')

@patch(
'linkcheck.models.PROXIES',
{'http': 'http://proxy.example.com:8080'},
)
@requests_mock.Mocker()
def test_external_proxy_request(self, mocker):
mocker.register_uri('HEAD', 'http://test.com', reason='OK'),
uv = Url(url='http://test.com')
self.assertEqual(mocker.called, False)
uv.check_url()
self.assertEqual(mocker.called, True)
self.assertEqual(uv.status, True)
self.assertEqual(uv.message, '200 OK')
self.assertEqual(uv.type, 'external')
last_request = mocker.last_request
self.assertEqual(last_request.hostname, 'test.com')
self.assertEqual(last_request.scheme, 'http')
self.assertEqual(last_request.proxies, {'http': 'http://proxy.example.com:8080'})

def test_external_check_timedout(self):
uv = Url(url=f"{self.live_server_url}/timeout/")
uv.check_url()
Expand Down
Loading