about summary refs log tree commit homepage
path: root/lib/mogilefs/mogilefs.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-17 18:34:15 -0700
committerEric Wong <normalperson@yhbt.net>2008-10-31 14:32:31 -0700
commitb36b892c735407bba34502e71e95d7481fc3ad79 (patch)
tree65bd0349b863c707183331cd37b7ae6b4bbb1aa6 /lib/mogilefs/mogilefs.rb
parent03fe01aa98e00ccf12f58e5bdb69d742e054fa36 (diff)
downloadmogilefs-client-b36b892c735407bba34502e71e95d7481fc3ad79.tar.gz
We'll be reusing it in the big file module
Diffstat (limited to 'lib/mogilefs/mogilefs.rb')
-rw-r--r--lib/mogilefs/mogilefs.rb28
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index 7ed66bd..fcb33d8 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -76,18 +76,8 @@ class MogileFS::MogileFS < MogileFS::Client
       next unless path
       case path
       when /^http:\/\// then
-        path = URI.parse(path)
-        sock = nil
         begin
-          timeout @get_file_data_timeout, MogileFS::Timeout do
-            sock = TCPSocket.new(path.host, path.port)
-            sock.sync = true
-            sock.syswrite("GET #{path.request_uri} HTTP/1.0\r\n\r\n")
-            buf = sock.recv(4096, Socket::MSG_PEEK)
-            head, body = buf.split(/\r\n\r\n/, 2)
-            head = sock.recv(head.size + 4)
-          end
-
+          sock = http_get_sock(URI.parse(path))
           return block_given? ? yield(sock) : sock.read
         rescue MogileFS::Timeout, Errno::ECONNREFUSED,
                EOFError, SystemCallError
@@ -270,5 +260,21 @@ class MogileFS::MogileFS < MogileFS::Client
     return keys, res['next_after']
   end
 
+  protected
+
+    def http_get_sock(uri)
+      sock = nil
+      timeout @get_file_data_timeout, MogileFS::Timeout do
+        sock = TCPSocket.new(uri.host, uri.port)
+        sock.sync = true
+        sock.syswrite("GET #{uri.request_uri} HTTP/1.0\r\n\r\n")
+        buf = sock.recv(4096, Socket::MSG_PEEK)
+        head, body = buf.split(/\r\n\r\n/, 2)
+        head = sock.recv(head.size + 4)
+      end
+
+      sock
+    end # def http_get_sock
+
 end