passiomatic / coldsweat

Web RSS aggregator and reader compatible with the Fever API
MIT License
146 stars 21 forks source link

Update feed URL after a "301 Moved permanently" #17

Closed passiomatic closed 11 years ago

passiomatic commented 11 years ago

Coldsweat currently tries to handle 301 status codes but fails given that Request package follows redirects automatically and response's status_code not reflect the original status returned.

To fix that Coldsweat should check the request history attr: http://docs.python-requests.org/en/latest/user/quickstart/#redirection-and-history

Case in point: http://feeds.feedburner.com/maxvoltar now http://maxvoltar.com/feed

HTTP/1.1 301 Moved Permanently
Location: http://maxvoltar.com/feed/
Content-Type: text/html; charset=UTF-8
Date: Sun, 28 Jul 2013 09:57:33 GMT
Expires: Sun, 28 Jul 2013 09:57:33 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked

<HTML>
<HEAD>
<TITLE>Moved Permanently</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Permanently</H1>
The document has moved <A HREF="http://maxvoltar.com/feed/">here</A>.
</BODY>
</HTML>

Note: Perhaps feed.alternate_link should also be updated after a 301 message.

passiomatic commented 11 years ago

Looks fixed. The way it works now is to check the first response from request.history array and to act accordingly. If there's more than one permanent redirect those will be updated in subsequents fetches.