Skip to content
Browse files

Fallback to GET when HEAD is not allowed.

  • Loading branch information...
1 parent b6c56ae commit 139b385fc1ea3a4fa4392d072e71cb93dca55caa @georgebrock georgebrock committed
Showing with 17 additions and 1 deletion.
  1. +4 −1 lib/helpers/uri_validator.rb
  2. +13 −0 spec/uri_validator_spec.rb
View
5 lib/helpers/uri_validator.rb
@@ -23,7 +23,10 @@ def uris
def valid_uri?(uri)
response = HTTParty.head(uri)
- return response.code == 200
+ if response.method_not_allowed?
+ response = HTTParty.get(uri)
+ end
+ return response.ok?
rescue SocketError
return false
end
View
13 spec/uri_validator_spec.rb
@@ -31,4 +31,17 @@
io.string.should =~ %r{ERROR in bad_json_file\.json: http://bad\.example\.org}
io.string.should =~ %r{ERROR in bad_json_file\.json: http://thoughtbot\.com/404}
end
+
+ it 'retries with a GET request on a method not allowed error' do
+ stub_request(:head, 'http://example.com').to_return(status: 405)
+ stub_request(:get, 'http://example.com')
+ file_name = 'rails.json'
+ URIExtractor.stubs(:new).with(file_name).returns %w(http://example.com)
+ $stdout = io = StringIO.new
+
+ URIValidator.new(file_name).run
+
+ WebMock.should have_requested(:head, 'http://example.com')
+ WebMock.should have_requested(:get, 'http://example.com')
+ end
end

0 comments on commit 139b385

Please sign in to comment.
Something went wrong with that request. Please try again.