about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/mogilefs/http_reader.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/mogilefs/http_reader.rb b/lib/mogilefs/http_reader.rb
index d3f57f7..47c893a 100644
--- a/lib/mogilefs/http_reader.rb
+++ b/lib/mogilefs/http_reader.rb
@@ -23,7 +23,7 @@ class MogileFS::HTTPReader < MogileFS::Socket
     errors = nil
     paths.each do |path|
       begin
-        sock = new(path, http_method, timeout) and return sock
+        sock = try(path, http_method, timeout) and return sock
       rescue => e
         errors ||= []
         errors << "#{path} failed with #{e.message} (#{e.class})"
@@ -35,7 +35,7 @@ class MogileFS::HTTPReader < MogileFS::Socket
 
   # given a path, this returns a readable socket with ready data from the
   # body of the response.
-  def self.new(path, http_method, timeout)
+  def self.try(path, http_method, timeout)
     uri = URI.parse(path)
     sock = tcp(uri.host, uri.port, timeout)
     buf = "#{http_method} #{uri.request_uri} HTTP/1.0\r\n\r\n" # no chunking
@@ -66,7 +66,7 @@ class MogileFS::HTTPReader < MogileFS::Socket
     raise MogileFS::InvalidResponseError,
           "#{http_method} on #{uri} returned: #{head.inspect}", []
   rescue
-    sock.close unless sock.closed?
+    sock.close if sock && ! sock.closed?
     raise
   end
 end