lib/etl/http_tools.rb in activewarehouse-etl-0.8.2 vs lib/etl/http_tools.rb in activewarehouse-etl-0.8.3
- old
+ new
@@ -5,11 +5,12 @@
# Parse the given user agent string
#
# Code taken from http://gemtacular.com/gems/ParseUserAgent
def parse_user_agent(user_agent)
if '-' == user_agent
- raise 'Invalid User Agent'
+ #raise 'Invalid User Agent'
+ puts 'Invalid User Agent'
end
browser, browser_version_major, browser_version_minor, ostype, os, os_version = nil
# fix Opera
@@ -104,15 +105,20 @@
end
result
end
def parse_uri(uri_string)
- if uri_string
- uri = URI.parse(uri_string)
-
- results = {:scheme => uri.scheme, :host => uri.host, :port => uri.port, :uri_path => uri.path}
- results[:domain] = $1 if uri.host =~ /\.?([^\.]+\.[^\.]+$)/
- results
+ if uri_string
+ #attempt to parse uri --if it's a uri then catch the problem and set everything to nil
+ begin
+ uri = URI.parse(uri_string)
+ results = {:scheme => uri.scheme, :host => uri.host, :port => uri.port, :uri_path => uri.path}
+ results[:domain] = $1 if uri.host =~ /\.?([^\.]+\.[^\.]+$)/
+ results
+ rescue
+ {:scheme => nil, :host => nil, :port => nil, :uri_path => nil, :domain => nil}
+ end
+
else
{:scheme => nil, :host => nil, :port => nil, :uri_path => nil, :domain => nil}
end
end
end
\ No newline at end of file