Skip to content

Commit

Permalink
Merge branch 'feature/optimize-ping-external-urls' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed May 2, 2015
2 parents 2eab48c + efb0e68 commit 477e528
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions zinnia/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ def find_pingback_urls(self, urls):
page = urlopen(url)
headers = page.info()

if 'text/' not in headers.get('Content-Type', '').lower():
continue

server_url = headers.get('X-Pingback')

if not server_url:
server_url = self.find_pingback_href(page.read())
content_type = headers.get('Content-Type', '').split(
';')[0].strip().lower()
if content_type in ['text/html', 'application/xhtml+xml']:
server_url = self.find_pingback_href(
page.read(5 * 1024))

if server_url:
server_url_splitted = urlsplit(server_url)
Expand Down
6 changes: 4 additions & 2 deletions zinnia/tests/test_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ def fake_urlopen(self, url):
if 'example' in url:
response = StringIO('')
return addinfourl(response, {'X-Pingback': '/xmlrpc.php',
'Content-Type': 'text/html'}, url)
'Content-Type':
'text/html; charset=utf-8'}, url)
elif 'localhost' in url:
response = StringIO(
'<link rel="pingback" href="/xmlrpc/">')
return addinfourl(response, {'Content-Type': 'text/xhtml'}, url)
return addinfourl(response, {'Content-Type':
'application/xhtml+xml'}, url)
elif 'google' in url:
response = StringIO('PNG CONTENT')
return addinfourl(response, {'content-type': 'image/png'}, url)
Expand Down

0 comments on commit 477e528

Please sign in to comment.