Skip to content

Commit

Permalink
Retry HEAD as GET if server returns 405 when
Browse files Browse the repository at this point in the history
  • Loading branch information
da2x committed Jul 27, 2015
1 parent e807212 commit c49ef8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -12,6 +12,7 @@ Features
Bugfixes
--------

* Retry HEAD as GET requests if server returns 405 when checking remote links
* Graceful fallback in ``nikola serve --detach`` on Windows (Issue #1913)
* Don't auto-rebuild on changes to ".foo" or "foo~" or changes in folders
* auto should also rebuild in response to move events
Expand Down
6 changes: 6 additions & 0 deletions nikola/plugins/command/check.py
Expand Up @@ -29,6 +29,7 @@
import os
import re
import sys
import time
try:
from urllib import unquote
from urlparse import urlparse, urljoin, urldefrag
Expand Down Expand Up @@ -223,6 +224,11 @@ def analyze(self, fname, find_sources=False, check_remote=False):
# Check the remote link works
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!
resp = requests.head(target, headers=req_headers)
# HEAD is not understood, so retry with a full GET after a half a second
if resp.status_code == 405:
time.sleep(0.5)
resp = requests.get(target, headers=req_headers)

self.checked_remote_targets[target] = resp.status_code
if resp.status_code > 399: # Error
self.logger.warn("Broken link in {0}: {1} [Error {2}]".format(filename, target, resp.status_code))
Expand Down

0 comments on commit c49ef8c

Please sign in to comment.