Skip to content

Commit

Permalink
Url control, adding http prefix if url didn't have it
Browse files Browse the repository at this point in the history
  • Loading branch information
javaguirre committed Jul 6, 2012
1 parent fd1d65a commit 40efb46
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/wappalyzer_rb.rb
Expand Up @@ -14,10 +14,22 @@ def initialize(url)
end

def self.get(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
http.request(request)
#TODO We could test with https too
if url.match(/^http/)
correct_url = url
else
correct_url = "http://#{url}"
end

uri = URI.parse(correct_url)

if uri.respond_to? 'request_uri'
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
http.request(request)
else
puts "Incorrect URI"
end
end

private
Expand Down Expand Up @@ -61,6 +73,10 @@ def response(url = nil)
url ||= @url
resp = WappalyzerRb::Detector.get(url)

if resp.nil?
Process.exit
end

redirects = 0
while resp.code == "302" && resp["location"] # redirect
raise 'Too many redirects' if redirects > 10
Expand Down

0 comments on commit 40efb46

Please sign in to comment.