class Feed2Email::RedirectionChecker
Attributes
location[R]
Public Class Methods
new(uri)
click to toggle source
# File lib/feed2email/redirection_checker.rb, line 8 def initialize(uri) @uri = uri check end
Public Instance Methods
permanently_redirected?()
click to toggle source
# File lib/feed2email/redirection_checker.rb, line 13 def permanently_redirected? redirected? && code == 301 end
Private Instance Methods
check()
click to toggle source
# File lib/feed2email/redirection_checker.rb, line 19 def check parsed_uri = URI.parse(uri) http = Net::HTTP.new(parsed_uri.host, parsed_uri.port) http.use_ssl = (parsed_uri.scheme == 'https') response = http.head(parsed_uri.request_uri) @code = response.code.to_i @location = response['location'] end
code()
click to toggle source
# File lib/feed2email/redirection_checker.rb, line 28 def code; @code end
redirected?()
click to toggle source
# File lib/feed2email/redirection_checker.rb, line 30 def redirected? [301, 302].include?(code) && location != uri && # prevent redirection to the same location location =~ %r{\Ahttps?://} # sanitize location end
uri()
click to toggle source
# File lib/feed2email/redirection_checker.rb, line 36 def uri; @uri end