Skip to content
Browse files

Fixing an issue around mal-formed requests aginst WordPress's Bad Beh…

…avior plugin, which checks for the 'Accept: *' header.
  • Loading branch information...
1 parent 5dd165b commit 396d76b5ace4caa2329907c3f29b139da29412c7 @samuelclay samuelclay committed Mar 19, 2012
Showing with 11 additions and 2 deletions.
  1. +9 −1 apps/rss_feeds/models.py
  2. +2 −1 utils/feedfinder.py
View
10 apps/rss_feeds/models.py
@@ -19,7 +19,7 @@
from apps.rss_feeds.tasks import UpdateFeeds
from celery.task import Task
from utils import json_functions as json
-from utils import feedfinder
+from utils import feedfinder, feedparser
from utils import urlnorm
from utils import log as logging
from utils.fields import AutoOneToOneField
@@ -187,7 +187,15 @@ def by_url(address):
if feed and len(feed) > offset:
feed = feed[offset]
elif create:
+ create_okay = False
if feedfinder.isFeed(url):
+ create_okay = True
+ elif aggressive:
+ # Could still be a feed. Just check if there are entries
+ fp = feedparser.parse(url)
+ if len(fp.entries):
+ create_okay = True
+ if create_okay:
feed = cls.objects.create(feed_address=url)
feed = feed.update()
View
3 utils/feedfinder.py
@@ -75,7 +75,7 @@ def __init__(self):
self.urlopener = urllib.FancyURLopener()
self.urlopener.version = "NewsBlur Feed Finder (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/534.48.3 (KHTML, like Gecko) Version/5.1 Safari/534.48.3)"
_debuglog(self.urlopener.version)
- self.urlopener.addheaders = [('User-agent', self.urlopener.version)]
+ self.urlopener.addheaders = [('User-agent', self.urlopener.version), ('Accept', '*')]
robotparser.URLopener.version = self.urlopener.version
robotparser.URLopener.addheaders = self.urlopener.addheaders
@@ -292,6 +292,7 @@ def feeds(uri, all=False, querySyndic8=False, _recurs=None):
if all or not outfeeds:
_debuglog('no A tags, guessing')
suffixes = [ # filenames used by popular software:
+ 'feed/', # obvious
'atom.xml', # blogger, TypePad
'index.atom', # MT, apparently
'index.rdf', # MT

0 comments on commit 396d76b

Please sign in to comment.
Something went wrong with that request. Please try again.