Skip to content

Commit c09c93c

Browse files
committedMay 19, 2015
Remote links all returned warnings when checked
Successes should return here too, would otherwise proceed down to line 256 and produce a warnig.
1 parent 7550c74 commit c09c93c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
 

‎CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Features
1010
Bugfixes
1111
--------
1212

13+
* All remotely checked links resulted in incorrect warnings (`nikola check -lr`)
1314
* Exclude `<meta content="noindex" name="robots">` from sitemaps
1415
* new_post paths are now relative to CWD (Issue #1325)
1516

‎nikola/plugins/command/check.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,16 @@ def analyze(self, task, find_sources=False, check_remote=False):
218218
if parsed.netloc == base_url.netloc:
219219
continue
220220
# Check the remote link works
221-
resp = requests.head(target)
221+
req_headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 (Nikola)'} # I’m a real boy!
222+
resp = requests.head(target, headers=req_headers)
222223
if resp.status_code > 399: # Error
223224
self.logger.warn("Broken link in {0}: {1} [Error {2}]".format(filename, target, resp.status_code))
224225
continue
226+
elif resp.status_code <= 399: # The address leads *somewhere* that is not an error
227+
self.logger.debug("Successfully checked remote link in {0}: {1} [HTTP: {2}]".format(filename, target, resp.status_code))
228+
continue
229+
self.logger.warn("Could not check remote link in {0}: {1} [Unknown problem]".format(filename, target))
230+
continue
225231

226232
if url_type == 'rel_path':
227233
target_filename = os.path.abspath(

0 commit comments

Comments
 (0)
Please sign in to comment.