I'm using the following code to make a request and follow redirects:
require 'faraday'
require 'faraday_middleware'
conn = Faraday.new() do |f|
f.use FaradayMiddleware::FollowRedirects, limit: 5
f.adapter Faraday.default_adapter
end
resp = conn.get('http://www.example.com/redirect')
resp.status
This code outputs 200 because it followed the redirect, which is great. But is there anyway to know if a redirect existed or not? something like resp.redirected
which is set to true
if a redirect was followed or false if no redirect was followed?
I didn't see anything obvious in the FollowRedirects code.
Will I need to write my own custom middleware if I want to know this? Does anyone know of middleware out there that might do this already?