From 9bcff8f08dc084b880ef978c890a2706a1bbb304 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 7 Nov 2011 23:17:41 +0000 Subject: http_reader: fix usage with pure sockets We won't redefine the "new" singleton method since that conflicts with existing usage. --- lib/mogilefs/http_reader.rb | 6 +++--- 1 file 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 -- cgit v1.2.3-24-ge0c7