lib/eat.rb in eat-0.1.0 vs lib/eat.rb in eat-0.1.1

- old
+ new

@@ -11,18 +11,21 @@ # <tt>url</tt> can be filesystem or http/https # # Options: # * <tt>:timeout</tt> in seconds # * <tt>:limit</tt> is characters (bytes in Ruby 1.8) + # * <tt>:openssl_verify_mode</tt> set to 'none' if you don't want to verify SSL certificates # # Example: # eat('http://brighterplanet.com') #=> '...' # eat('http://brighterplanet.com', :timeout => 10) #=> '...' # eat('http://brighterplanet.com', :limit => 1) #=> '.' def eat(url, options = {}) timeout = options[:timeout] || options['timeout'] || 2 limit = options[:limit] || options['limit'] || ::Infinity + openssl_verify_mode = options[:openssl_verify_mode] || options['openssl_verify_mode'] + uri = ::URI.parse url.to_s body = [] read_so_far = 0 @@ -43,11 +46,10 @@ require 'net/https' if uri.scheme == 'https' (defined?(::SystemTimer) ? ::SystemTimer : ::Timeout).timeout(timeout) do http = ::Net::HTTP.new uri.host, uri.port if uri.scheme == 'https' http.use_ssl = true - # if you were trying to be real safe, you wouldn't use this library - http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE + http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE if openssl_verify_mode.to_s == 'none' end http.start do |session| catch :stop do session.get(uri.request_uri, 'Accept-Encoding' => '') do |chunk| throw :stop if read_so_far > limit