0

Is there a way to detect a redirection in Ruby ?

I just want to know if the link gets redirected, without downloading a page and checking for exceptions.

The faster it is, the better.

  • does this help [get-redirect-of-a-url-in-ruby](https://stackoverflow.com/questions/5872210/get-redirect-of-a-url-in-ruby) – max pleaner May 22 '17 at 18:13

1 Answers1

1

http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-i-head

response = nil
Net::HTTP.start('some.www.server', 80) {|http|
  response = http.head('/index.html')
}

head call gets just only the header and you can check the response code to detect the redirection.

coffeebytes
  • 376
  • 1
  • 3
  • 7