Permalink
Browse files

Merge pull request #1506 from duckpuppy/handle-multiple-redirects

gist_plugin: Handle multiple redirects, stopping if we find a circular r...
  • Loading branch information...
2 parents 0ead88e + a66e031 commit b86880352b421ad8884355ba2e2dea9b92c65996 @parkr parkr committed Mar 4, 2014
Showing with 5 additions and 1 deletion.
  1. +5 −1 plugins/gist_tag.rb
View
@@ -78,8 +78,11 @@ def get_gist_from_web(gist, file)
gist_url = get_gist_url_for(gist, file)
data = get_web_content(gist_url)
- if data.code.to_i == 302
+ locations = Array.new
+ while (data.code.to_i == 301 || data.code.to_i == 302)
data = handle_gist_redirecting(data)
+ break if locations.include? data.header['Location']
+ locations << data.header['Location']
end
if data.code.to_i != 200
@@ -95,6 +98,7 @@ def handle_gist_redirecting(data)
if redirected_url.nil? || redirected_url.empty?
raise ArgumentError, "GitHub replied with a 302 but didn't provide a location in the response headers."
end
+
get_web_content(redirected_url)
end

0 comments on commit b868803

Please sign in to comment.