http icon indicating copy to clipboard operation
http copied to clipboard

Add on_redirect callback.

Open benubois opened this issue 3 years ago • 0 comments

Hello,

This adds an on_redirect callback that can be passed to .follow. For example:

permanent_redirects = []
HTTP.follow(
  max_hops: 4, 
  on_redirect: proc do |from, to|
    permanent_redirects.push({ from: from.uri.to_s, to: to.uri.to_s }) if [301, 308].include?(from.status.code)
  end
).get("…")

I found this feature to be useful while trying to come up with a redirect caching system.

Thanks!

benubois avatar Aug 04 '22 00:08 benubois