uber-s3 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,15 +12,7 @@ module UberS3::Connection
12
12
  self.uri = URI.parse(url)
13
13
 
14
14
  # Init and open a HTTP connection
15
- self.http ||= Net::HTTP.new(uri.host, uri.port)
16
- if !http.started? || !http.active?
17
- http.start
18
-
19
- if Socket.const_defined?(:TCP_NODELAY)
20
- socket = http.instance_variable_get(:@socket)
21
- socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
22
- end
23
- end
15
+ http_connect! if http.nil? || !http.started?
24
16
 
25
17
  req_klass = instance_eval("Net::HTTP::"+verb.to_s.capitalize)
26
18
  req = req_klass.new(uri.to_s, headers)
@@ -28,9 +20,15 @@ module UberS3::Connection
28
20
  req.body = body if !body.nil? && !body.empty?
29
21
 
30
22
  # Make HTTP request
31
- r = http.request(req)
32
-
33
- # $stderr.puts "active? " + http.active?.to_s
23
+ retries = 2
24
+ begin
25
+ r = http.request(req)
26
+ rescue EOFError, Errno::EPIPE
27
+ # Something happened to our connection, lets try this again
28
+ http_connect!
29
+ retries -= 1
30
+ retry if retries >= 0
31
+ end
34
32
 
35
33
  # Auto-decode any gzipped objects
36
34
  if verb == :get && r.header['Content-Encoding'] == 'gzip'
@@ -47,6 +45,18 @@ module UberS3::Connection
47
45
  :raw => r
48
46
  })
49
47
  end
48
+
49
+ private
50
+
51
+ def http_connect!
52
+ self.http = Net::HTTP.new(uri.host, uri.port)
53
+ http.start
54
+
55
+ if Socket.const_defined?(:TCP_NODELAY)
56
+ socket = http.instance_variable_get(:@socket)
57
+ socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
58
+ end
59
+ end
50
60
 
51
61
  end
52
62
  end
@@ -1,3 +1,3 @@
1
1
  class UberS3
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uber-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-28 00:00:00.000000000 Z
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types