Thanks Jeremy,
That is very helpful :) I might take a look on open-uri, but this looks like it will serve my purposes. Until now I have been doing something like this:
...
def handle_redirects()
@resp.body.downcase
!
redirectLinkBegin = (@resp.body.split(/href="/))[1]
redirectLink = (redirectLinkBegin.split(/"/))[0]
if !(redirectLink['://'].nil?)
hostString = redirectLink.split
(/:\/\//)[1]
@host = (hostString.split(/\//))[0]
pathOffset = hostString.index('/')
if !(pathOffset.nil?)
@path = hostString.slice(pathOffset, (hostString.length - 1))
end # End: if pathOffset > -1
if @debug
puts 'Redirecting to: ' + @host
end
@http = Net::HTTP.new @host, @portNumber
else
if @debug
puts 'Redirecting to: ' + redirectLink.to_s
end
@path = redirectLink
end # End: if !(redirectLink['://'].nil?)
end # End: def handle_redirects()
Which works for a particular flavor of redirects, but I don't know if it works for every kind of redirect. I don't have many test resources, nor do I know of many sites that use redirects to test it on.
Thanks,
Nathan
Nathan Lane