Skip to content
Browse files

Switched from net/http to patron (excellent libcurl lib) for more per…

…formance and resilience.
  • Loading branch information...
1 parent 1a8a3bf commit 30aa8764bf484ecf990150eb0389e7e1b0ce7b1d @tobi committed
Showing with 16 additions and 5 deletions.
  1. +16 −5 lib/image.rb
View
21 lib/image.rb
@@ -1,6 +1,6 @@
require 'RMagick'
require 'fileutils'
-require 'net/http'
+require 'patron'
class Image
attr_accessor :content
@@ -43,15 +43,26 @@ def dirname
end
private
+
+ def session
+ @@session ||= begin
+ sess = Patron::Session.new
+ sess.timeout = 10
+ sess.headers['User-Agent'] = 'imagery/1.0'
+ sess
+ end
+ end
+
+ def download(path_info)
+ session.base_url = "http://#{server}"
- def download(path_info)
response = Logger.current.info_with_time "Loading http://#{server}#{path_info}" do
- Net::HTTP.get_response(server, path_info)
+ session.get(path_info)
end
@path = path_info.split('?')[0]
- @headers = response
- @status = response.code.to_i
+ @headers = response.headers
+ @status = response.status
if found?
self.content = response.body

0 comments on commit 30aa876

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