excon 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of excon might be problematic. Click here for more details.
- data/benchmarks/merging.rb +21 -0
- data/benchmarks/vs_stdlib.rb +82 -0
- data/excon.gemspec +4 -2
- data/lib/excon.rb +1 -1
- data/lib/excon/connection.rb +8 -13
- metadata +6 -4
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'tach'
|
3
|
+
|
4
|
+
Tach.meter(10_000) do
|
5
|
+
|
6
|
+
tach('merge') do
|
7
|
+
default = { :a => 1, :b => 2 }
|
8
|
+
override = { :b => 3, :c => 4 }
|
9
|
+
override = default.merge(override)
|
10
|
+
end
|
11
|
+
|
12
|
+
tach('loop') do
|
13
|
+
default = { :a => 1, :b => 2 }
|
14
|
+
override = { :b => 3, :c => 4 }
|
15
|
+
for key, value in default
|
16
|
+
override[key] ||= default[key]
|
17
|
+
end
|
18
|
+
override
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'tach'
|
5
|
+
|
6
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'excon')
|
7
|
+
|
8
|
+
module Excon
|
9
|
+
class Server < Sinatra::Base
|
10
|
+
|
11
|
+
def self.run
|
12
|
+
Rack::Handler::WEBrick.run(
|
13
|
+
Excon::Server.new,
|
14
|
+
:Port => 9292,
|
15
|
+
:AccessLog => [],
|
16
|
+
:Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/data/:amount' do |amount|
|
21
|
+
'x' * amount.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_server(&block)
|
28
|
+
pid = Process.fork do
|
29
|
+
Excon::Server.run
|
30
|
+
end
|
31
|
+
loop do
|
32
|
+
sleep(1)
|
33
|
+
begin
|
34
|
+
Excon.get('http://localhost:9292/api/foo')
|
35
|
+
break
|
36
|
+
rescue
|
37
|
+
end
|
38
|
+
end
|
39
|
+
yield
|
40
|
+
ensure
|
41
|
+
Process.kill(9, pid)
|
42
|
+
end
|
43
|
+
|
44
|
+
require 'net/http'
|
45
|
+
require 'open-uri'
|
46
|
+
|
47
|
+
url = 'http://localhost:9292/data/1000'
|
48
|
+
|
49
|
+
with_server do
|
50
|
+
|
51
|
+
Tach.meter(100) do
|
52
|
+
|
53
|
+
tach('Excon') do
|
54
|
+
Excon.get(url).body
|
55
|
+
end
|
56
|
+
|
57
|
+
# tach('Excon (persistent)') do |times|
|
58
|
+
# excon = Excon.new(url)
|
59
|
+
# times.times do
|
60
|
+
# excon.request(:method => 'get').body
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
|
64
|
+
tach('Net::HTTP') do
|
65
|
+
# Net::HTTP.get('localhost', '/data/1000', 9292)
|
66
|
+
Net::HTTP.start('localhost', 9292) {|http| http.get('/data/1000').body }
|
67
|
+
end
|
68
|
+
|
69
|
+
# tach('Net::HTTP (persistent)') do |times|
|
70
|
+
# Net::HTTP.start('localhost', 9292) do |http|
|
71
|
+
# times.times do
|
72
|
+
# http.get('/data/1000').body
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
|
77
|
+
# tach('open-uri') do
|
78
|
+
# open(url).read
|
79
|
+
# end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/excon.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'excon'
|
16
|
-
s.version = '0.3.
|
17
|
-
s.date = '2010-12-
|
16
|
+
s.version = '0.3.4'
|
17
|
+
s.date = '2010-12-13'
|
18
18
|
s.rubyforge_project = 'excon'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -70,7 +70,9 @@ Gem::Specification.new do |s|
|
|
70
70
|
benchmarks/cr_lf.rb
|
71
71
|
benchmarks/excon_vs.rb
|
72
72
|
benchmarks/headers_split_vs_match.rb
|
73
|
+
benchmarks/merging.rb
|
73
74
|
benchmarks/strip_newline.rb
|
75
|
+
benchmarks/vs_stdlib.rb
|
74
76
|
excon.gemspec
|
75
77
|
lib/excon.rb
|
76
78
|
lib/excon/connection.rb
|
data/lib/excon.rb
CHANGED
data/lib/excon/connection.rb
CHANGED
@@ -26,7 +26,7 @@ module Excon
|
|
26
26
|
:query => uri.query,
|
27
27
|
:scheme => uri.scheme
|
28
28
|
}.merge!(params)
|
29
|
-
|
29
|
+
@socket_key = "#{@connection[:host]}:#{@connection[:port]}"
|
30
30
|
reset
|
31
31
|
end
|
32
32
|
|
@@ -90,8 +90,10 @@ module Excon
|
|
90
90
|
end
|
91
91
|
|
92
92
|
# add headers to request
|
93
|
-
for key,
|
94
|
-
|
93
|
+
for key, values in params[:headers]
|
94
|
+
for value in [*values]
|
95
|
+
request << key.to_s << ': ' << value.to_s << CR_NL
|
96
|
+
end
|
95
97
|
end
|
96
98
|
|
97
99
|
# add additional "\r\n" to indicate end of headers
|
@@ -146,7 +148,7 @@ module Excon
|
|
146
148
|
end
|
147
149
|
|
148
150
|
def reset
|
149
|
-
(old_socket = sockets.delete(socket_key)) && old_socket.close
|
151
|
+
(old_socket = sockets.delete(@socket_key)) && old_socket.close
|
150
152
|
end
|
151
153
|
|
152
154
|
private
|
@@ -178,26 +180,19 @@ module Excon
|
|
178
180
|
end
|
179
181
|
|
180
182
|
def closed?
|
181
|
-
sockets[socket_key] && sockets[socket_key].closed?
|
183
|
+
sockets[@socket_key] && sockets[@socket_key].closed?
|
182
184
|
end
|
183
185
|
|
184
186
|
def socket
|
185
187
|
if closed?
|
186
188
|
reset
|
187
189
|
end
|
188
|
-
sockets[socket_key] ||= connect
|
190
|
+
sockets[@socket_key] ||= connect
|
189
191
|
end
|
190
192
|
|
191
193
|
def sockets
|
192
194
|
Thread.current[:_excon_sockets] ||= {}
|
193
195
|
end
|
194
196
|
|
195
|
-
def socket_key
|
196
|
-
@connection[:socket_key]
|
197
|
-
end
|
198
|
-
|
199
|
-
def set_socket_key
|
200
|
-
@connection[:socket_key] = "#{@connection[:host]}:#{@connection[:port]}"
|
201
|
-
end
|
202
197
|
end
|
203
198
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- geemus (Wesley Beary)
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-13 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -79,7 +79,9 @@ files:
|
|
79
79
|
- benchmarks/cr_lf.rb
|
80
80
|
- benchmarks/excon_vs.rb
|
81
81
|
- benchmarks/headers_split_vs_match.rb
|
82
|
+
- benchmarks/merging.rb
|
82
83
|
- benchmarks/strip_newline.rb
|
84
|
+
- benchmarks/vs_stdlib.rb
|
83
85
|
- excon.gemspec
|
84
86
|
- lib/excon.rb
|
85
87
|
- lib/excon/connection.rb
|