excon 0.30.0 → 0.31.0
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.lock +1 -1
- data/README.md +68 -1
- data/changelog.txt +14 -0
- data/excon.gemspec +5 -3
- data/lib/excon.rb +2 -2
- data/lib/excon/connection.rb +19 -8
- data/lib/excon/constants.rb +2 -1
- data/lib/excon/errors.rb +48 -41
- data/lib/excon/utils.rb +15 -3
- data/tests/authorization_header_tests.rb +7 -6
- data/tests/basic_tests.rb +1 -2
- data/tests/header_tests.rb +5 -2
- data/tests/middlewares/canned_response_tests.rb +5 -8
- data/tests/middlewares/decompress_tests.rb +34 -27
- data/tests/middlewares/instrumentation_tests.rb +11 -10
- data/tests/middlewares/mock_tests.rb +50 -48
- data/tests/middlewares/redirect_follower_tests.rb +47 -49
- data/tests/pipeline_tests.rb +40 -0
- data/tests/proxy_tests.rb +23 -18
- data/tests/query_string_tests.rb +16 -16
- data/tests/rackups/basic.rb +4 -0
- data/tests/rackups/proxy.ru +4 -0
- data/tests/rackups/query_string.ru +4 -0
- data/tests/rackups/request_headers.ru +4 -0
- data/tests/rackups/request_methods.ru +6 -2
- data/tests/rackups/response_header.ru +4 -0
- data/tests/rackups/thread_safety.ru +4 -0
- data/tests/rackups/timeout.ru +5 -0
- data/tests/rackups/webrick_patch.rb +34 -0
- data/tests/request_method_tests.rb +2 -2
- data/tests/request_tests.rb +113 -0
- data/tests/response_tests.rb +20 -14
- data/tests/servers/good.rb +38 -21
- data/tests/test_helper.rb +43 -23
- data/tests/thread_safety_tests.rb +3 -3
- data/tests/timeout_tests.rb +2 -3
- metadata +6 -4
- data/tests/requests_tests.rb +0 -73
@@ -0,0 +1,40 @@
|
|
1
|
+
Shindo.tests('Pipelined Requests') do
|
2
|
+
with_server('good') do
|
3
|
+
|
4
|
+
tests('with default :persistent => true') do
|
5
|
+
returns(%w{ 1 2 3 4 }, 'connection is persistent') do
|
6
|
+
connection = Excon.new('http://127.0.0.1:9292', :persistent => true)
|
7
|
+
|
8
|
+
ret = []
|
9
|
+
ret << connection.requests([
|
10
|
+
{:method => :get, :path => '/echo/request_count'},
|
11
|
+
{:method => :get, :path => '/echo/request_count'}
|
12
|
+
]).map(&:body)
|
13
|
+
ret << connection.requests([
|
14
|
+
{:method => :get, :path => '/echo/request_count'},
|
15
|
+
{:method => :get, :path => '/echo/request_count'}
|
16
|
+
]).map(&:body)
|
17
|
+
ret.flatten
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
tests('with default :persistent => false') do
|
22
|
+
returns(%w{ 1 2 1 2 }, 'connection is persistent per call to #requests') do
|
23
|
+
connection = Excon.new('http://127.0.0.1:9292', :persistent => false)
|
24
|
+
|
25
|
+
ret = []
|
26
|
+
ret << connection.requests([
|
27
|
+
{:method => :get, :path => '/echo/request_count'},
|
28
|
+
{:method => :get, :path => '/echo/request_count'}
|
29
|
+
]).map(&:body)
|
30
|
+
ret << connection.requests([
|
31
|
+
{:method => :get, :path => '/echo/request_count'},
|
32
|
+
{:method => :get, :path => '/echo/request_count'}
|
33
|
+
]).map(&:body)
|
34
|
+
ret.flatten
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/tests/proxy_tests.rb
CHANGED
@@ -4,17 +4,17 @@ Shindo.tests('Excon proxy support') do
|
|
4
4
|
tests('proxy configuration') do
|
5
5
|
|
6
6
|
tests('no proxy') do
|
7
|
-
connection = Excon.new('http://foo.com')
|
8
|
-
|
9
7
|
tests('connection.data[:proxy]').returns(nil) do
|
8
|
+
connection = Excon.new('http://foo.com')
|
10
9
|
connection.data[:proxy]
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
tests('with fully-specified proxy: https://myproxy.net:8080') do
|
15
|
-
connection =
|
14
|
+
connection = nil
|
16
15
|
|
17
16
|
tests('connection.data[:proxy][:host]').returns('myproxy.net') do
|
17
|
+
connection = Excon.new('http://foo.com', :proxy => 'https://myproxy.net:8080')
|
18
18
|
connection.data[:proxy][:host]
|
19
19
|
end
|
20
20
|
|
@@ -31,9 +31,10 @@ Shindo.tests('Excon proxy support') do
|
|
31
31
|
env_init(env)
|
32
32
|
|
33
33
|
tests('an http connection') do
|
34
|
-
connection =
|
34
|
+
connection = nil
|
35
35
|
|
36
36
|
tests('connection.data[:proxy][:host]').returns('myproxy') do
|
37
|
+
connection = Excon.new('http://foo.com')
|
37
38
|
connection.data[:proxy][:host]
|
38
39
|
end
|
39
40
|
|
@@ -47,9 +48,10 @@ Shindo.tests('Excon proxy support') do
|
|
47
48
|
end
|
48
49
|
|
49
50
|
tests('an https connection') do
|
50
|
-
connection =
|
51
|
+
connection = nil
|
51
52
|
|
52
53
|
tests('connection.data[:proxy][:host]').returns('mysecureproxy') do
|
54
|
+
connection = Excon.new('https://secret.com')
|
53
55
|
connection.data[:proxy][:host]
|
54
56
|
end
|
55
57
|
|
@@ -63,9 +65,10 @@ Shindo.tests('Excon proxy support') do
|
|
63
65
|
end
|
64
66
|
|
65
67
|
tests('http proxy from the environment overrides config') do
|
66
|
-
connection =
|
68
|
+
connection = nil
|
67
69
|
|
68
70
|
tests('connection.data[:proxy][:host]').returns('myproxy') do
|
71
|
+
connection = Excon.new('http://foo.com', :proxy => 'http://hard.coded.proxy:6666')
|
69
72
|
connection.data[:proxy][:host]
|
70
73
|
end
|
71
74
|
|
@@ -75,25 +78,22 @@ Shindo.tests('Excon proxy support') do
|
|
75
78
|
end
|
76
79
|
|
77
80
|
tests('an http connection in no_proxy') do
|
78
|
-
|
79
|
-
|
80
|
-
tests('connection.data[:proxy]').returns(nil) do
|
81
|
+
tests('connection.data[:proxy]').returns(nil) do
|
82
|
+
connection = Excon.new('http://somesubdomain.noproxy')
|
81
83
|
connection.data[:proxy]
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
87
|
tests('an http connection not completely matching no_proxy') do
|
86
|
-
connection = Excon.new('http://noproxy2')
|
87
|
-
|
88
88
|
tests('connection.data[:proxy][:host]').returns('myproxy') do
|
89
|
+
connection = Excon.new('http://noproxy2')
|
89
90
|
connection.data[:proxy][:host]
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
94
|
tests('an http connection with subdomain in no_proxy') do
|
94
|
-
connection = Excon.new('http://a.subdomain.noproxy2')
|
95
|
-
|
96
95
|
tests('connection.data[:proxy]').returns(nil) do
|
96
|
+
connection = Excon.new('http://a.subdomain.noproxy2')
|
97
97
|
connection.data[:proxy]
|
98
98
|
end
|
99
99
|
end
|
@@ -119,9 +119,10 @@ Shindo.tests('Excon proxy support') do
|
|
119
119
|
env_init({'http_proxy' => 'http://myproxy:8080' })
|
120
120
|
|
121
121
|
tests('an https connection') do
|
122
|
-
connection =
|
122
|
+
connection = nil
|
123
123
|
|
124
124
|
tests('connection.data[:proxy][:host]').returns('myproxy') do
|
125
|
+
connection = Excon.new('https://secret.com')
|
125
126
|
connection.data[:proxy][:host]
|
126
127
|
end
|
127
128
|
|
@@ -142,10 +143,12 @@ Shindo.tests('Excon proxy support') do
|
|
142
143
|
with_rackup('proxy.ru') do
|
143
144
|
|
144
145
|
tests('http proxying: http://foo.com:8080') do
|
145
|
-
|
146
|
-
response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
|
146
|
+
response = nil
|
147
147
|
|
148
148
|
tests('response.status').returns(200) do
|
149
|
+
connection = Excon.new('http://foo.com:8080', :proxy => 'http://127.0.0.1:9292')
|
150
|
+
response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
|
151
|
+
|
149
152
|
response.status
|
150
153
|
end
|
151
154
|
|
@@ -168,10 +171,12 @@ Shindo.tests('Excon proxy support') do
|
|
168
171
|
end
|
169
172
|
|
170
173
|
tests('http proxying: http://user:pass@foo.com:8080') do
|
171
|
-
|
172
|
-
response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
|
174
|
+
response = nil
|
173
175
|
|
174
176
|
tests('response.status').returns(200) do
|
177
|
+
connection = Excon.new('http://foo.com:8080', :proxy => 'http://user:pass@127.0.0.1:9292')
|
178
|
+
response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
|
179
|
+
|
175
180
|
response.status
|
176
181
|
end
|
177
182
|
|
data/tests/query_string_tests.rb
CHANGED
@@ -1,35 +1,34 @@
|
|
1
1
|
Shindo.tests('Excon query string variants') do
|
2
2
|
with_rackup('query_string.ru') do
|
3
|
-
connection =
|
3
|
+
connection = nil
|
4
4
|
|
5
5
|
tests(":query => {:foo => 'bar'}") do
|
6
|
+
tests("query string sent").returns('foo=bar') do
|
7
|
+
connection = Excon.new('http://127.0.0.1:9292')
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar'})
|
10
|
+
query_string = response.body[7..-1] # query string sent
|
9
11
|
|
10
|
-
tests("query string sent").returns('foo=bar') do
|
11
12
|
query_string
|
12
13
|
end
|
13
|
-
|
14
14
|
end
|
15
15
|
|
16
16
|
tests(":query => {:foo => nil}") do
|
17
|
-
|
18
|
-
response = connection.request(:method => :get, :path => '/query', :query => {:foo => nil})
|
19
|
-
query_string = response.body[7..-1] # query string sent
|
20
|
-
|
21
17
|
tests("query string sent").returns('foo') do
|
18
|
+
response = connection.request(:method => :get, :path => '/query', :query => {:foo => nil})
|
19
|
+
query_string = response.body[7..-1] # query string sent
|
20
|
+
|
22
21
|
query_string
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
24
|
|
27
25
|
tests(":query => {:foo => 'bar', :me => nil}") do
|
28
|
-
|
29
|
-
response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar', :me => nil})
|
30
|
-
query_string = response.body[7..-1] # query string sent
|
26
|
+
query_string = nil
|
31
27
|
|
32
28
|
test("query string sent includes 'foo=bar'") do
|
29
|
+
response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar', :me => nil})
|
30
|
+
query_string = response.body[7..-1] # query string sent
|
31
|
+
|
33
32
|
query_string.split('&').include?('foo=bar')
|
34
33
|
end
|
35
34
|
|
@@ -40,11 +39,12 @@ Shindo.tests('Excon query string variants') do
|
|
40
39
|
end
|
41
40
|
|
42
41
|
tests(":query => {:foo => 'bar', :me => 'too'}") do
|
43
|
-
|
44
|
-
response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar', :me => 'too'})
|
45
|
-
query_string = response.body[7..-1] # query string sent
|
42
|
+
query_string = nil
|
46
43
|
|
47
44
|
test("query string sent includes 'foo=bar'") do
|
45
|
+
response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar', :me => 'too'})
|
46
|
+
query_string = response.body[7..-1] # query string sent
|
47
|
+
|
48
48
|
query_string.split('&').include?('foo=bar')
|
49
49
|
end
|
50
50
|
|
data/tests/rackups/basic.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'sinatra'
|
2
|
+
require File.join(File.dirname(__FILE__), 'webrick_patch')
|
2
3
|
|
3
4
|
class Basic < Sinatra::Base
|
5
|
+
set :environment, :production
|
6
|
+
enable :dump_errors
|
7
|
+
|
4
8
|
get('/content-length/:value') do |value|
|
5
9
|
headers("Custom" => "Foo: bar")
|
6
10
|
'x' * value.to_i
|
data/tests/rackups/proxy.ru
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require 'sinatra'
|
2
|
+
require File.join(File.dirname(__FILE__), 'webrick_patch')
|
2
3
|
|
3
4
|
class App < Sinatra::Base
|
5
|
+
set :environment, :production
|
6
|
+
enable :dump_errors
|
7
|
+
|
4
8
|
get '/' do
|
5
9
|
'GET'
|
6
10
|
end
|
7
|
-
|
11
|
+
|
8
12
|
post '/' do
|
9
13
|
'POST'
|
10
14
|
end
|
11
|
-
|
15
|
+
|
12
16
|
delete '/' do
|
13
17
|
'DELETE'
|
14
18
|
end
|
data/tests/rackups/timeout.ru
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# The ruby 2.0 stdlib includes the following changes
|
2
|
+
# to avoid "can't add a new key into hash during iteration" errors.
|
3
|
+
# https://github.com/ruby/ruby/commit/3c491a92f6fbfecc065f7687c51c7d6d52a38883
|
4
|
+
# https://github.com/ruby/ruby/commit/7b18633804c606e8bcccfbb44e7d7b795e777ea6
|
5
|
+
# However, these changes were not backported to the 1.9.x stdlib.
|
6
|
+
# These errors are causing intermittent errors in the tests (frequently in jruby),
|
7
|
+
# so we're applying those changes here. This is loaded by all rackups using WEBrick.
|
8
|
+
if RUBY_VERSION =~ /^1\.9/
|
9
|
+
require 'webrick/utils'
|
10
|
+
module WEBrick
|
11
|
+
module Utils
|
12
|
+
class TimeoutHandler
|
13
|
+
def initialize
|
14
|
+
@timeout_info = Hash.new
|
15
|
+
Thread.start{
|
16
|
+
while true
|
17
|
+
now = Time.now
|
18
|
+
@timeout_info.keys.each{|thread|
|
19
|
+
ary = @timeout_info[thread]
|
20
|
+
next unless ary
|
21
|
+
ary.dup.each{|info|
|
22
|
+
time, exception = *info
|
23
|
+
interrupt(thread, info.object_id, exception) if time < now
|
24
|
+
}
|
25
|
+
}
|
26
|
+
sleep 0.5
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -19,10 +19,10 @@ Shindo.tests('Excon request methods') do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
tests 'with a connection object' do
|
22
|
-
|
23
|
-
connection = Excon.new('http://localhost:9292')
|
22
|
+
connection = nil
|
24
23
|
|
25
24
|
tests('connection.get').returns('GET') do
|
25
|
+
connection = Excon.new('http://localhost:9292')
|
26
26
|
connection.get.body
|
27
27
|
end
|
28
28
|
|
@@ -0,0 +1,113 @@
|
|
1
|
+
Shindo.tests('Request Tests') do
|
2
|
+
with_server('good') do
|
3
|
+
|
4
|
+
tests('sets transfer-coding and connection options') do
|
5
|
+
|
6
|
+
tests('without a :response_block') do
|
7
|
+
request = nil
|
8
|
+
|
9
|
+
returns('trailers, deflate, gzip', 'sets encoding options') do
|
10
|
+
request = Marshal.load(
|
11
|
+
Excon.get('http://127.0.0.1:9292/echo/request').body
|
12
|
+
)
|
13
|
+
|
14
|
+
request[:headers]['TE']
|
15
|
+
end
|
16
|
+
|
17
|
+
returns(true, 'TE added to Connection header') do
|
18
|
+
request[:headers]['Connection'].include?('TE')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
tests('with a :response_block') do
|
23
|
+
request = nil
|
24
|
+
|
25
|
+
returns('trailers', 'does not set encoding options') do
|
26
|
+
captures = capture_response_block do |block|
|
27
|
+
Excon.get('http://127.0.0.1:9292/echo/request',
|
28
|
+
:response_block => block)
|
29
|
+
end
|
30
|
+
data = captures.map {|capture| capture[0] }.join
|
31
|
+
request = Marshal.load(data)
|
32
|
+
|
33
|
+
request[:headers]['TE']
|
34
|
+
end
|
35
|
+
|
36
|
+
returns(true, 'TE added to Connection header') do
|
37
|
+
request[:headers]['Connection'].include?('TE')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
tests('persistent connections') do
|
44
|
+
|
45
|
+
tests('with default :persistent => true') do
|
46
|
+
connection = nil
|
47
|
+
|
48
|
+
returns(['1', '2'], 'uses a persistent connection') do
|
49
|
+
connection = Excon.new('http://127.0.0.1:9292', :persistent => true)
|
50
|
+
2.times.map do
|
51
|
+
connection.request(:method => :get, :path => '/echo/request_count').body
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
returns(['3', '1', '2'], ':persistent => false resets connection') do
|
56
|
+
ret = []
|
57
|
+
ret << connection.request(:method => :get,
|
58
|
+
:path => '/echo/request_count',
|
59
|
+
:persistent => false).body
|
60
|
+
ret << connection.request(:method => :get,
|
61
|
+
:path => '/echo/request_count').body
|
62
|
+
ret << connection.request(:method => :get,
|
63
|
+
:path => '/echo/request_count').body
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
tests('with default :persistent => false') do
|
68
|
+
connection = nil
|
69
|
+
|
70
|
+
returns(['1', '1'], 'does not use a persistent connection') do
|
71
|
+
connection = Excon.new('http://127.0.0.1:9292', :persistent => false)
|
72
|
+
2.times.map do
|
73
|
+
connection.request(:method => :get, :path => '/echo/request_count').body
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
returns(['1', '2', '3', '1'], ':persistent => true enables persistence') do
|
78
|
+
ret = []
|
79
|
+
ret << connection.request(:method => :get,
|
80
|
+
:path => '/echo/request_count',
|
81
|
+
:persistent => true).body
|
82
|
+
ret << connection.request(:method => :get,
|
83
|
+
:path => '/echo/request_count',
|
84
|
+
:persistent => true).body
|
85
|
+
ret << connection.request(:method => :get,
|
86
|
+
:path => '/echo/request_count').body
|
87
|
+
ret << connection.request(:method => :get,
|
88
|
+
:path => '/echo/request_count').body
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
tests('sends `Connection: close`') do
|
93
|
+
returns(true, 'when :persistent => false') do
|
94
|
+
request = Marshal.load(
|
95
|
+
Excon.get('http://127.0.0.1:9292/echo/request',
|
96
|
+
:persistent => false).body
|
97
|
+
)
|
98
|
+
request[:headers]['Connection'].include?('close')
|
99
|
+
end
|
100
|
+
|
101
|
+
returns(false, 'not when :persistent => true') do
|
102
|
+
request = Marshal.load(
|
103
|
+
Excon.get('http://127.0.0.1:9292/echo/request',
|
104
|
+
:persistent => true).body
|
105
|
+
)
|
106
|
+
request[:headers]['Connection'].include?('close')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|