excon 0.0.5 → 0.0.7
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/Gemfile +14 -0
- data/VERSION +1 -1
- data/benchmarks/excon_vs.rb +23 -0
- data/bin/rackup +3 -0
- data/bin/shindo +3 -0
- data/excon.gemspec +8 -6
- data/lib/excon/connection.rb +16 -10
- data/tests/config.ru +10 -0
- data/tests/mock_tests.rb +40 -0
- data/tests/test_helper.rb +14 -0
- data/tests/threaded_tests.rb +24 -0
- metadata +12 -7
- data/test/test.rb +0 -30
data/Gemfile
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/benchmarks/excon_vs.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
Bundler.require_env(:benchmarks)
|
2
|
+
|
1
3
|
require File.join(File.dirname(__FILE__), '..', 'lib/excon')
|
2
4
|
|
3
5
|
require 'benchmark'
|
@@ -36,4 +38,25 @@ Benchmark.bmbm(25) do |bench|
|
|
36
38
|
open('http://www.google.com/').read
|
37
39
|
end
|
38
40
|
end
|
41
|
+
bench.report('em') do
|
42
|
+
module DumbHttpClient
|
43
|
+
@@responses = 0
|
44
|
+
def post_init
|
45
|
+
send_data "GET / HTTP/1.1\r\nHost: _\r\n\r\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
def receive_data(*)
|
49
|
+
@@responses += 1
|
50
|
+
if @@responses == COUNT
|
51
|
+
EM.stop
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
EM.run{
|
57
|
+
COUNT.times do
|
58
|
+
EM.connect 'www.google.com', 80, DumbHttpClient
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
39
62
|
end
|
data/bin/rackup
ADDED
data/bin/shindo
ADDED
data/excon.gemspec
CHANGED
@@ -5,19 +5,21 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{excon}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Wesley Beary"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-21}
|
13
13
|
s.description = %q{speed, persistence, http(s)}
|
14
14
|
s.email = %q{wbeary@engineyard.com}
|
15
|
+
s.executables = ["rackup", "shindo"]
|
15
16
|
s.extra_rdoc_files = [
|
16
17
|
"README.rdoc"
|
17
18
|
]
|
18
19
|
s.files = [
|
19
20
|
".document",
|
20
21
|
".gitignore",
|
22
|
+
"Gemfile",
|
21
23
|
"README.rdoc",
|
22
24
|
"Rakefile",
|
23
25
|
"VERSION",
|
@@ -29,16 +31,16 @@ Gem::Specification.new do |s|
|
|
29
31
|
"lib/excon/connection.rb",
|
30
32
|
"lib/excon/errors.rb",
|
31
33
|
"lib/excon/response.rb",
|
32
|
-
"
|
34
|
+
"tests/config.ru",
|
35
|
+
"tests/mock_tests.rb",
|
36
|
+
"tests/test_helper.rb",
|
37
|
+
"tests/threaded_tests.rb"
|
33
38
|
]
|
34
39
|
s.homepage = %q{http://github.com/geemus/excon}
|
35
40
|
s.rdoc_options = ["--charset=UTF-8"]
|
36
41
|
s.require_paths = ["lib"]
|
37
42
|
s.rubygems_version = %q{1.3.5}
|
38
43
|
s.summary = %q{EXtended http(s) CONnections}
|
39
|
-
s.test_files = [
|
40
|
-
"test/test.rb"
|
41
|
-
]
|
42
44
|
|
43
45
|
if s.respond_to? :specification_version then
|
44
46
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/lib/excon/connection.rb
CHANGED
@@ -92,19 +92,25 @@ unless Excon.mocking?
|
|
92
92
|
private
|
93
93
|
|
94
94
|
def connection
|
95
|
-
if
|
96
|
-
|
97
|
-
if @uri.scheme == 'https'
|
98
|
-
@ssl_context = OpenSSL::SSL::SSLContext.new
|
99
|
-
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
100
|
-
@connection = OpenSSL::SSL::SSLSocket.new(@connection, @ssl_context)
|
101
|
-
@connection.sync_close = true
|
102
|
-
@connection.connect
|
103
|
-
end
|
95
|
+
if !Thread.current[:_excon_connection] || Thread.current[:_excon_connection].closed?
|
96
|
+
Thread.current[:_excon_connection] = establish_connection
|
104
97
|
end
|
105
|
-
|
98
|
+
Thread.current[:_excon_connection]
|
106
99
|
end
|
107
100
|
|
101
|
+
def establish_connection
|
102
|
+
connection = TCPSocket.open(@uri.host, @uri.port)
|
103
|
+
|
104
|
+
if @uri.scheme == 'https'
|
105
|
+
@ssl_context = OpenSSL::SSL::SSLContext.new
|
106
|
+
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
107
|
+
connection = OpenSSL::SSL::SSLSocket.new(connection, @ssl_context)
|
108
|
+
connection.sync_close = true
|
109
|
+
connection.connect
|
110
|
+
end
|
111
|
+
|
112
|
+
connection
|
113
|
+
end
|
108
114
|
end
|
109
115
|
end
|
110
116
|
|
data/tests/config.ru
ADDED
data/tests/mock_tests.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
Excon.mock!
|
4
|
+
|
5
|
+
request = {
|
6
|
+
:host => 'www.google.com',
|
7
|
+
:method => 'GET',
|
8
|
+
:path => '/'
|
9
|
+
}
|
10
|
+
response = Excon::Response.new({
|
11
|
+
:status => 200,
|
12
|
+
:headers => { 'Content-Length' => '11' },
|
13
|
+
:body => 'Hello World'
|
14
|
+
})
|
15
|
+
Excon.mocks[request] = response
|
16
|
+
|
17
|
+
Shindo.tests do
|
18
|
+
|
19
|
+
before do
|
20
|
+
@connection = Excon.new('http://www.google.com')
|
21
|
+
@response = @connection.request({
|
22
|
+
:host => 'www.google.com',
|
23
|
+
:method => 'GET',
|
24
|
+
:path => '/'
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
test("status => 200") do
|
29
|
+
@response.status == 200
|
30
|
+
end
|
31
|
+
|
32
|
+
test("headers => { 'Content-Length' => '11' }") do
|
33
|
+
@response.headers == { 'Content-Length' => '11' }
|
34
|
+
end
|
35
|
+
|
36
|
+
test("body => 'Hello World") do
|
37
|
+
@response.body == 'Hello World'
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/excon'))
|
2
|
+
|
3
|
+
Bundler.require_env(:test)
|
4
|
+
|
5
|
+
def local_file(*parts)
|
6
|
+
File.expand_path(File.join(File.dirname(__FILE__), *parts))
|
7
|
+
end
|
8
|
+
|
9
|
+
def with_rackup(configru = local_file('config.ru'), rackup = local_file('..', 'bin', 'rackup'))
|
10
|
+
pid, w, r, e = Open4.popen4("#{rackup} #{configru}")
|
11
|
+
while `lsof -p #{pid} -P -i | grep ruby | grep TCP`.chomp.empty?; end
|
12
|
+
yield
|
13
|
+
Process.kill(9, pid)
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
with_rackup do
|
4
|
+
Shindo.tests do
|
5
|
+
test('threaded requests') do
|
6
|
+
connection = Excon.new('http://127.0.0.1:9292')
|
7
|
+
|
8
|
+
long_thread = Thread.new {
|
9
|
+
response = connection.request(:method => 'GET', :path => '/id/1/wait/2')
|
10
|
+
Thread.current[:success] = response.body == '1'
|
11
|
+
}
|
12
|
+
|
13
|
+
short_thread = Thread.new {
|
14
|
+
response = connection.request(:method => 'GET', :path => '/id/2/wait/1')
|
15
|
+
Thread.current[:success] = response.body == '2'
|
16
|
+
}
|
17
|
+
|
18
|
+
long_thread.join
|
19
|
+
short_thread.join
|
20
|
+
|
21
|
+
long_thread[:success] && short_thread[:success]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wesley Beary
|
@@ -9,14 +9,15 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-21 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: speed, persistence, http(s)
|
17
17
|
email: wbeary@engineyard.com
|
18
|
-
executables:
|
19
|
-
|
18
|
+
executables:
|
19
|
+
- rackup
|
20
|
+
- shindo
|
20
21
|
extensions: []
|
21
22
|
|
22
23
|
extra_rdoc_files:
|
@@ -24,6 +25,7 @@ extra_rdoc_files:
|
|
24
25
|
files:
|
25
26
|
- .document
|
26
27
|
- .gitignore
|
28
|
+
- Gemfile
|
27
29
|
- README.rdoc
|
28
30
|
- Rakefile
|
29
31
|
- VERSION
|
@@ -35,7 +37,10 @@ files:
|
|
35
37
|
- lib/excon/connection.rb
|
36
38
|
- lib/excon/errors.rb
|
37
39
|
- lib/excon/response.rb
|
38
|
-
-
|
40
|
+
- tests/config.ru
|
41
|
+
- tests/mock_tests.rb
|
42
|
+
- tests/test_helper.rb
|
43
|
+
- tests/threaded_tests.rb
|
39
44
|
has_rdoc: true
|
40
45
|
homepage: http://github.com/geemus/excon
|
41
46
|
licenses: []
|
@@ -64,5 +69,5 @@ rubygems_version: 1.3.5
|
|
64
69
|
signing_key:
|
65
70
|
specification_version: 3
|
66
71
|
summary: EXtended http(s) CONnections
|
67
|
-
test_files:
|
68
|
-
|
72
|
+
test_files: []
|
73
|
+
|
data/test/test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'lib/excon')
|
2
|
-
|
3
|
-
Excon.mock!
|
4
|
-
|
5
|
-
request = {
|
6
|
-
:host => 'www.google.com',
|
7
|
-
:method => 'GET',
|
8
|
-
:path => '/'
|
9
|
-
}
|
10
|
-
response = {
|
11
|
-
:status => 200,
|
12
|
-
:headers => { 'Content-Length' => '11' },
|
13
|
-
:body => 'Hello World'
|
14
|
-
}
|
15
|
-
Excon.mocks[request] = response
|
16
|
-
|
17
|
-
x = Excon.new('http://www.google.com')
|
18
|
-
|
19
|
-
10.times do
|
20
|
-
p x.request(
|
21
|
-
:host => 'www.google.com',
|
22
|
-
:method => 'GET',
|
23
|
-
:path => '/'
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
# require 'open-uri'
|
28
|
-
# 10.times do
|
29
|
-
# p open('http://www.google.com').read
|
30
|
-
# end
|