Scott Watermasysk

Still Learning to Code

Announcing: Unwind Gem

Unwind has a single goal. Take a url and figure out what it actually points to.

It is able to walk various redirect status codes, handles relative and absolute locations, and a couple of other gotchas.

Once completed you have the destination url and a list of the hops along the way.

1
2
3
4
require 'unwind'

follower = Unwind::RedirectFollower.resolve('http://j.mp/Ai8S1s')
assert_equal 'http://www.scottw.com/unwind', follower.final_url

Hat Tip: This gem started with code from John Nunemaker’s Following Redirects with Net/HTTP which provided the basic code to get this done.