lib/unwind.rb in unwind-0.9.4 vs lib/unwind.rb in unwind-0.9.5

- old
+ new

@@ -31,10 +31,14 @@ if [301, 302, 303].include?(response.status) @redirects << current_url.to_s @redirect_limit -= 1 resolve(redirect_url(response).normalize, apply_cookie(response, headers)) + elsif response.status == 200 && meta_uri = meta_refresh?(response) + @redirects << current_url.to_s + @redirect_limit -= 1 + resolve(meta_uri.normalize, apply_cookie(response, headers)) else @final_url = current_url.to_s @response = response self end @@ -59,9 +63,14 @@ Addressable::URI.parse(body_match[0]) else redirect_uri = Addressable::URI.parse(response['location']) redirect_uri.relative? ? response.env[:url].join(response['location']) : redirect_uri end + end + + def meta_refresh?(response) + body_match = response.body.match(/<meta http-equiv=\"refresh\" content=\"0; URL=(.*)\">/i) + body_match ? Addressable::URI.parse(body_match[1]) : false end def apply_cookie(response, headers) if response.status == 302 && response['set-cookie'] headers.merge(:cookie => CookieHash.to_cookie_string(response['set-cookie']))