Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add net-http-persistent support; bump version to 0.1.7

  • Loading branch information...
commit 28954c0a5ab6416074783889005472162890f0cc 1 parent 3a663b4
Peter Kieltyka authored
View
4 lib/uber-s3/connection.rb
@@ -23,7 +23,7 @@ def initialize(client, options={})
self.client = client
self.access_key = options[:access_key]
self.secret_access_key = options[:secret_access_key]
- self.persistent = options[:persistent] || true
+ self.persistent = (options[:persistent].nil? ? true : options[:persistent])
self.defaults = options[:defaults] || {}
end
@@ -36,7 +36,7 @@ def initialize(client, options={})
# Default headers
headers['Date'] = Time.now.httpdate if !headers.keys.include?('Date')
headers['User-Agent'] ||= "UberS3 v#{UberS3::VERSION}"
- # headers['Connection'] = (persistent ? 'keep-alive' : 'close')
+ headers['Connection'] = (persistent ? 'keep-alive' : 'close')
if body
headers['Content-Length'] ||= body.bytesize.to_s
View
16 lib/uber-s3/connection/net_http.rb
@@ -1,4 +1,5 @@
require 'net/http'
+require 'net/http/persistent'
module UberS3::Connection
class NetHttp < Adapter
@@ -10,12 +11,23 @@ def request(verb, url, headers={}, body=nil)
end
uri = URI.parse(url)
- http = Net::HTTP.new(uri.host, uri.port)
+
+ if persistent
+ http = Net::HTTP::Persistent.new("#{access_key}:#{client.bucket}")
+ else
+ http = Net::HTTP.new(uri.host, uri.port)
+ end
req_klass = instance_eval("Net::HTTP::"+verb.to_s.capitalize)
req = req_klass.new(uri.to_s, headers)
+
+ req.body = body if !body.nil? && !body.empty?
- r = http.request(req, body)
+ if persistent
+ r = http.request(uri, req)
+ else
+ r = http.request(req)
+ end
# Auto-decode any gzipped objects
if verb == :get && r.header['content-encoding'] == 'gzip'
View
2  lib/uber-s3/version.rb
@@ -1,3 +1,3 @@
class UberS3
- VERSION = '0.1.6'
+ VERSION = '0.1.7'
end
View
18 spec/uber-s3/object_spec.rb
@@ -2,7 +2,8 @@
describe UberS3::Object do
[:net_http, :em_http_fibered].each do |connection_adapter|
-
+ # [:net_http].each do |connection_adapter|
+
context "#{connection_adapter}: Object" do
let(:s3) do
UberS3.new({
@@ -70,6 +71,21 @@
content_length.should < value.bytesize
end
end
+
+ it 'keep persistent connection with many objects saved' do
+ # NOTE: currently this doesn't actually confirm we've kept
+ # a persistent connection open.. just helps with empirical testing
+ spec(s3) do
+ dummy_data = "A"*1024
+
+ 25.times do
+ rand_key = (0...8).map{65.+(rand(25)).chr}.join
+ s3.store(rand_key, dummy_data)
+ # puts "Storing #{rand_key}"
+ end
+
+ end
+ end
end
View
1  uber-s3.gemspec
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.add_dependency('mime-types', ['~> 1.17'])
+ s.add_dependency('net-http-persistent', ['~> 2.5'])
s.add_development_dependency('rake')
s.add_development_dependency('rspec', ['~> 2.7.0'])
Please sign in to comment.
Something went wrong with that request. Please try again.