about summary refs log tree commit homepage
path: root/lib/mogilefs/http_reader.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mogilefs/http_reader.rb')
-rw-r--r--lib/mogilefs/http_reader.rb25
1 files changed, 8 insertions, 17 deletions
diff --git a/lib/mogilefs/http_reader.rb b/lib/mogilefs/http_reader.rb
index 76ba328..ca0e46b 100644
--- a/lib/mogilefs/http_reader.rb
+++ b/lib/mogilefs/http_reader.rb
@@ -19,30 +19,30 @@ class MogileFS::HTTPReader < MogileFS::Socket
           "read=#{buf.size} bytes, expected=#@content_length from #@uri", []
   end
 
-  def self.first(paths, http_method, timeout)
+  def self.first(paths, timeout)
     errors = nil
     paths.each do |path|
       begin
-        sock = try(path, http_method, timeout) and return sock
+        sock = try(path, timeout) and return sock
       rescue => e
         errors ||= []
         errors << "#{path} - #{e.message} (#{e.class})"
       end
     end
     raise MogileFS::Error,
-          "all paths failed with #{http_method}: #{errors.join(', ')}", []
+          "all paths failed with GET: #{errors.join(', ')}", []
   end
 
   # given a path, this returns a readable socket with ready data from the
   # body of the response.
-  def self.try(path, http_method, timeout)
+  def self.try(path, 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
+    buf = "GET #{uri.request_uri} HTTP/1.0\r\n\r\n" # no chunking
     sock.timed_write(buf, timeout)
 
     sock.timed_peek(2048, buf, timeout) or
-      raise MogileFS::InvalidResponseError, "EOF on #{http_method} #{uri}", []
+      raise MogileFS::InvalidResponseError, "EOF while reading header", []
 
     head, _ = buf.split(/\r\n\r\n/, 2)
 
@@ -52,19 +52,10 @@ class MogileFS::HTTPReader < MogileFS::Socket
        head =~ %r{^Content-Length:\s*(\d+)}i
       sock.content_length = $1.to_i
       sock.uri = uri
-
-      case http_method
-      when "HEAD"
-        sock.close
-      else # "GET"
-        # slice off the top of the socket buffer to allow IO.copy_stream
-        # to work
-        sock.timed_read(head.bytesize + 4, buf, 0)
-      end
+      sock.timed_read(head.bytesize + 4, buf, 0)
       return sock
     end
-    raise MogileFS::InvalidResponseError,
-          "#{http_method} on #{uri} returned: #{head.inspect}", []
+    raise MogileFS::InvalidResponseError, "header=#{head.inspect}", []
   rescue
     sock.close if sock && ! sock.closed?
     raise