Added support for http redirects.
This commit is contained in:
parent
4eb177fc70
commit
e6837fb79b
1 changed files with 7 additions and 0 deletions
|
@ -7,7 +7,14 @@ module RSS
|
|||
begin
|
||||
puts 'fetch rss...'
|
||||
response = Net::HTTP.get_response( URI.parse(url) )
|
||||
|
||||
# check if redirect is needed
|
||||
if response.code.to_s == '301' || response.code.to_s == '302'
|
||||
url = response.header['location']
|
||||
response = Net::HTTP.get_response( URI.parse( url ) )
|
||||
end
|
||||
if response.code.to_s != '200'
|
||||
raise "Can't fetch '#{url}', http code: #{response.code.to_s}"
|
||||
return
|
||||
end
|
||||
rss = SimpleRSS.parse response.body
|
||||
|
|
Loading…
Reference in a new issue