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.

@@ -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
@@ -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 = Excon.new('http://foo.com', :proxy => 'https://myproxy.net:8080')
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 = Excon.new('http://foo.com')
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 = Excon.new('https://secret.com')
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 = Excon.new('http://foo.com', :proxy => 'http://hard.coded.proxy:6666')
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
- connection = Excon.new('http://somesubdomain.noproxy')
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 = Excon.new('https://secret.com')
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
- connection = Excon.new('http://foo.com:8080', :proxy => 'http://127.0.0.1:9292')
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
- connection = Excon.new('http://foo.com:8080', :proxy => 'http://user:pass@127.0.0.1:9292')
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
 
@@ -1,35 +1,34 @@
1
1
  Shindo.tests('Excon query string variants') do
2
2
  with_rackup('query_string.ru') do
3
- connection = Excon.new('http://127.0.0.1:9292')
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
- response = connection.request(:method => :get, :path => '/query', :query => {:foo => 'bar'})
8
- query_string = response.body[7..-1] # query string sent
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
 
@@ -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
@@ -1,6 +1,10 @@
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
  headers(
6
10
  "Sent-Request-Uri" => request.env['REQUEST_URI'].to_s,
@@ -1,6 +1,10 @@
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('/query') do
5
9
  "query: " << request.query_string
6
10
  end
@@ -1,6 +1,10 @@
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
  post '/' do
5
9
  h = ""
6
10
  env.each { |k,v| h << "#{$1.downcase}: #{v}\n" if k =~ /http_(.*)/i }
@@ -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
@@ -1,6 +1,10 @@
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('/foo') do
5
9
  headers(
6
10
  "MixedCase-Header" => 'MixedCase',
@@ -1,6 +1,10 @@
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('/id/:id/wait/:wait') do |id, wait|
5
9
  sleep(wait.to_i)
6
10
  id.to_s
@@ -1,8 +1,13 @@
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('/timeout') do
5
9
  sleep(2)
10
+ ''
6
11
  end
7
12
  end
8
13
 
@@ -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