excon 0.62.0 → 0.79.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.md +1 -1
  3. data/README.md +5 -4
  4. data/data/cacert.pem +769 -1496
  5. data/excon.gemspec +17 -2
  6. data/lib/excon.rb +25 -17
  7. data/lib/excon/connection.rb +193 -119
  8. data/lib/excon/constants.rb +36 -13
  9. data/lib/excon/error.rb +15 -0
  10. data/lib/excon/headers.rb +4 -3
  11. data/lib/excon/instrumentors/logging_instrumentor.rb +4 -15
  12. data/lib/excon/instrumentors/standard_instrumentor.rb +2 -9
  13. data/lib/excon/middlewares/base.rb +6 -0
  14. data/lib/excon/middlewares/capture_cookies.rb +1 -1
  15. data/lib/excon/middlewares/decompress.rb +2 -2
  16. data/lib/excon/middlewares/expects.rb +7 -1
  17. data/lib/excon/middlewares/idempotent.rb +20 -3
  18. data/lib/excon/middlewares/instrumentor.rb +8 -0
  19. data/lib/excon/middlewares/mock.rb +12 -3
  20. data/lib/excon/middlewares/redirect_follower.rb +25 -3
  21. data/lib/excon/middlewares/response_parser.rb +3 -0
  22. data/lib/excon/pretty_printer.rb +1 -8
  23. data/lib/excon/response.rb +12 -9
  24. data/lib/excon/socket.rb +38 -21
  25. data/lib/excon/ssl_socket.rb +24 -13
  26. data/lib/excon/test/plugin/server/exec.rb +2 -2
  27. data/lib/excon/test/server.rb +1 -1
  28. data/lib/excon/unix_socket.rb +1 -0
  29. data/lib/excon/utils.rb +41 -5
  30. data/lib/excon/version.rb +1 -1
  31. metadata +27 -98
  32. data/.document +0 -5
  33. data/.gitignore +0 -13
  34. data/.rspec +0 -3
  35. data/.travis.yml +0 -29
  36. data/Gemfile +0 -19
  37. data/Rakefile +0 -41
  38. data/benchmarks/class_vs_lambda.rb +0 -50
  39. data/benchmarks/concat_vs_insert.rb +0 -21
  40. data/benchmarks/concat_vs_interpolate.rb +0 -22
  41. data/benchmarks/cr_lf.rb +0 -21
  42. data/benchmarks/downcase-eq-eq_vs_casecmp.rb +0 -169
  43. data/benchmarks/excon.rb +0 -69
  44. data/benchmarks/excon_vs.rb +0 -165
  45. data/benchmarks/for_vs_array_each.rb +0 -27
  46. data/benchmarks/for_vs_hash_each.rb +0 -27
  47. data/benchmarks/has_key-vs-lookup.rb +0 -177
  48. data/benchmarks/headers_case_sensitivity.rb +0 -83
  49. data/benchmarks/headers_split_vs_match.rb +0 -34
  50. data/benchmarks/implicit_block-vs-explicit_block.rb +0 -98
  51. data/benchmarks/merging.rb +0 -21
  52. data/benchmarks/single_vs_double_quotes.rb +0 -21
  53. data/benchmarks/string_ranged_index.rb +0 -87
  54. data/benchmarks/strip_newline.rb +0 -115
  55. data/benchmarks/vs_stdlib.rb +0 -82
  56. data/changelog.txt +0 -1083
  57. data/spec/excon/error_spec.rb +0 -139
  58. data/spec/excon/test/server_spec.rb +0 -28
  59. data/spec/excon_spec.rb +0 -7
  60. data/spec/helpers/file_path_helpers.rb +0 -22
  61. data/spec/requests/basic_spec.rb +0 -40
  62. data/spec/requests/eof_requests_spec.rb +0 -36
  63. data/spec/requests/unix_socket_spec.rb +0 -46
  64. data/spec/spec_helper.rb +0 -24
  65. data/spec/support/shared_contexts/test_server_context.rb +0 -83
  66. data/spec/support/shared_examples/shared_example_for_clients.rb +0 -218
  67. data/spec/support/shared_examples/shared_example_for_streaming_clients.rb +0 -20
  68. data/spec/support/shared_examples/shared_example_for_test_servers.rb +0 -16
  69. data/tests/authorization_header_tests.rb +0 -29
  70. data/tests/bad_tests.rb +0 -47
  71. data/tests/basic_tests.rb +0 -351
  72. data/tests/batch_requests.rb +0 -133
  73. data/tests/complete_responses.rb +0 -31
  74. data/tests/data/127.0.0.1.cert.crt +0 -20
  75. data/tests/data/127.0.0.1.cert.key +0 -27
  76. data/tests/data/excon.cert.crt +0 -20
  77. data/tests/data/excon.cert.key +0 -27
  78. data/tests/data/xs +0 -1
  79. data/tests/error_tests.rb +0 -145
  80. data/tests/header_tests.rb +0 -119
  81. data/tests/middlewares/canned_response_tests.rb +0 -34
  82. data/tests/middlewares/capture_cookies_tests.rb +0 -34
  83. data/tests/middlewares/decompress_tests.rb +0 -157
  84. data/tests/middlewares/escape_path_tests.rb +0 -36
  85. data/tests/middlewares/idempotent_tests.rb +0 -206
  86. data/tests/middlewares/instrumentation_tests.rb +0 -315
  87. data/tests/middlewares/mock_tests.rb +0 -304
  88. data/tests/middlewares/redirect_follower_tests.rb +0 -112
  89. data/tests/pipeline_tests.rb +0 -40
  90. data/tests/proxy_tests.rb +0 -306
  91. data/tests/query_string_tests.rb +0 -87
  92. data/tests/rackups/basic.rb +0 -41
  93. data/tests/rackups/basic.ru +0 -3
  94. data/tests/rackups/basic_auth.ru +0 -14
  95. data/tests/rackups/deflater.ru +0 -4
  96. data/tests/rackups/proxy.ru +0 -18
  97. data/tests/rackups/query_string.ru +0 -13
  98. data/tests/rackups/redirecting.ru +0 -23
  99. data/tests/rackups/redirecting_with_cookie.ru +0 -40
  100. data/tests/rackups/request_headers.ru +0 -15
  101. data/tests/rackups/request_methods.ru +0 -21
  102. data/tests/rackups/response_header.ru +0 -18
  103. data/tests/rackups/ssl.ru +0 -16
  104. data/tests/rackups/ssl_mismatched_cn.ru +0 -15
  105. data/tests/rackups/ssl_verify_peer.ru +0 -16
  106. data/tests/rackups/streaming.ru +0 -30
  107. data/tests/rackups/thread_safety.ru +0 -17
  108. data/tests/rackups/timeout.ru +0 -14
  109. data/tests/rackups/webrick_patch.rb +0 -34
  110. data/tests/request_headers_tests.rb +0 -21
  111. data/tests/request_method_tests.rb +0 -47
  112. data/tests/request_tests.rb +0 -59
  113. data/tests/response_tests.rb +0 -197
  114. data/tests/servers/bad.rb +0 -20
  115. data/tests/servers/eof.rb +0 -17
  116. data/tests/servers/error.rb +0 -20
  117. data/tests/servers/good.rb +0 -350
  118. data/tests/test_helper.rb +0 -306
  119. data/tests/thread_safety_tests.rb +0 -39
  120. data/tests/timeout_tests.rb +0 -12
  121. data/tests/utils_tests.rb +0 -81
@@ -1,112 +0,0 @@
1
- Shindo.tests('Excon redirector support') do
2
- env_init
3
-
4
- tests("request(:method => :get, :path => '/old').body").returns('new') do
5
- Excon.stub(
6
- { :path => '/old' },
7
- {
8
- :headers => { 'Location' => 'http://127.0.0.1:9292/new' },
9
- :body => 'old',
10
- :status => 301
11
- }
12
- )
13
-
14
- Excon.stub(
15
- { :path => '/new' },
16
- {
17
- :body => 'new',
18
- :status => 200
19
- }
20
- )
21
-
22
- Excon.get(
23
- 'http://127.0.0.1:9292',
24
- :path => '/old',
25
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
26
- :mock => true
27
- ).body
28
- end
29
-
30
- env_restore
31
- end
32
-
33
- Shindo.tests('Excon redirect support for relative Location headers') do
34
- env_init
35
-
36
- tests("request(:method => :get, :path => '/old').body").returns('new') do
37
- Excon.stub(
38
- { :path => '/old' },
39
- {
40
- :headers => { 'Location' => '/new' },
41
- :body => 'old',
42
- :status => 301
43
- }
44
- )
45
-
46
- Excon.stub(
47
- { :path => '/new' },
48
- {
49
- :body => 'new',
50
- :status => 200
51
- }
52
- )
53
-
54
- Excon.get(
55
- 'http://127.0.0.1:9292',
56
- :path => '/old',
57
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
58
- :mock => true
59
- ).body
60
- end
61
-
62
- env_restore
63
- end
64
-
65
- Shindo.tests('Excon redirect support for relative Location headers with dot segments') do
66
- env_init
67
-
68
- tests("request(:method => :get, :path => '/foo/baz/').body").returns('/foo/bar/') do
69
- Excon.stub(
70
- { :path => '/foo/baz/' },
71
- {
72
- :headers => { 'Location' => '../bar/' },
73
- :body => '/foo/baz/',
74
- :status => 301
75
- }
76
- )
77
-
78
- Excon.stub(
79
- { :path => '/foo/bar/' },
80
- {
81
- :body => '/foo/bar/',
82
- :status => 200
83
- }
84
- )
85
-
86
- Excon.get(
87
- 'http://127.0.0.1:9292',
88
- :path => '/foo/baz/',
89
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
90
- :mock => true
91
- ).body
92
- end
93
-
94
- env_restore
95
- end
96
-
97
- Shindo.tests("Excon redirecting post request") do
98
- env_init
99
-
100
- with_rackup('redirecting.ru') do
101
- tests("request not have content-length and body").returns('ok') do
102
- Excon.post(
103
- 'http://127.0.0.1:9292',
104
- :path => '/first',
105
- :middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
106
- :body => "a=Some_content"
107
- ).body
108
- end
109
- end
110
-
111
- env_restore
112
- end
@@ -1,40 +0,0 @@
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 DELETED
@@ -1,306 +0,0 @@
1
- Shindo.tests('Excon proxy support') do
2
- env_init
3
-
4
- tests('proxy configuration') do
5
-
6
- tests('no proxy') do
7
- tests('connection.data[:proxy]').returns(nil) do
8
- connection = Excon.new('http://foo.com')
9
- connection.data[:proxy]
10
- end
11
- end
12
-
13
- tests('empty proxy') do
14
- tests('connection.data[:proxy]').returns(nil) do
15
- connection = Excon.new('http://foo.com', :proxy => '')
16
- connection.data[:proxy]
17
- end
18
- end
19
-
20
- tests('with fully-specified proxy: https://myproxy.net:8080') do
21
- connection = nil
22
-
23
- tests('connection.data[:proxy][:host]').returns('myproxy.net') do
24
- connection = Excon.new('http://foo.com', :proxy => 'https://myproxy.net:8080')
25
- connection.data[:proxy][:host]
26
- end
27
-
28
- tests('connection.data[:proxy][:port]').returns(8080) do
29
- connection.data[:proxy][:port]
30
- end
31
-
32
- tests('connection.data[:proxy][:scheme]').returns('https') do
33
- connection.data[:proxy][:scheme]
34
- end
35
- end
36
-
37
- tests('with fully-specified Unix socket proxy: unix:///') do
38
- connection = nil
39
-
40
- tests('connection.data[:proxy][:host]').returns(nil) do
41
- connection = Excon.new('http://foo.com', :proxy => 'unix:///tmp/myproxy.sock')
42
- connection.data[:proxy][:host]
43
- end
44
-
45
- tests('connection.data[:proxy][:port]').returns(nil) do
46
- connection.data[:proxy][:port]
47
- end
48
-
49
- tests('connection.data[:proxy][:scheme]').returns('unix') do
50
- connection.data[:proxy][:scheme]
51
- end
52
-
53
- tests('connection.data[:proxy][:path]').returns('/tmp/myproxy.sock') do
54
- connection.data[:proxy][:path]
55
- end
56
- end
57
-
58
- def env_proxy_tests(env)
59
- env_init(env)
60
-
61
- tests('an http connection') do
62
- connection = nil
63
-
64
- tests('connection.data[:proxy][:host]').returns('myproxy') do
65
- connection = Excon.new('http://foo.com')
66
- connection.data[:proxy][:host]
67
- end
68
-
69
- tests('connection.data[:proxy][:port]').returns(8080) do
70
- connection.data[:proxy][:port]
71
- end
72
-
73
- tests('connection.data[:proxy][:scheme]').returns('http') do
74
- connection.data[:proxy][:scheme]
75
- end
76
-
77
- tests('with disable_proxy set') do
78
- connection = nil
79
-
80
- tests('connection.data[:proxy]').returns(nil) do
81
- connection = Excon.new('http://foo.com', :disable_proxy => true)
82
- connection.data[:proxy]
83
- end
84
- end
85
- end
86
-
87
- tests('an https connection') do
88
- connection = nil
89
-
90
- tests('connection.data[:proxy][:host]').returns('mysecureproxy') do
91
- connection = Excon.new('https://secret.com')
92
- connection.data[:proxy][:host]
93
- end
94
-
95
- tests('connection.data[:proxy][:port]').returns(8081) do
96
- connection.data[:proxy][:port]
97
- end
98
-
99
- tests('connection.data[:proxy][:scheme]').returns('http') do
100
- connection.data[:proxy][:scheme]
101
- end
102
-
103
- tests('with disable_proxy set') do
104
- connection = nil
105
-
106
- tests('connection.data[:proxy]').returns(nil) do
107
- connection = Excon.new('https://foo.com', :disable_proxy => true)
108
- connection.data[:proxy]
109
- end
110
- end
111
- end
112
-
113
- tests('http proxy from the environment overrides config') do
114
- connection = nil
115
-
116
- tests('connection.data[:proxy][:host]').returns('myproxy') do
117
- connection = Excon.new('http://foo.com', :proxy => 'http://hard.coded.proxy:6666')
118
- connection.data[:proxy][:host]
119
- end
120
-
121
- tests('connection.data[:proxy][:port]').returns(8080) do
122
- connection.data[:proxy][:port]
123
- end
124
- end
125
-
126
- tests('an http connection in no_proxy') do
127
- tests('connection.data[:proxy]').returns(nil) do
128
- connection = Excon.new('http://somesubdomain.noproxy')
129
- connection.data[:proxy]
130
- end
131
- end
132
-
133
- tests('an http connection not completely matching no_proxy') do
134
- tests('connection.data[:proxy][:host]').returns('myproxy') do
135
- connection = Excon.new('http://noproxy2')
136
- connection.data[:proxy][:host]
137
- end
138
- end
139
-
140
- tests('an http connection with subdomain in no_proxy') do
141
- tests('connection.data[:proxy]').returns(nil) do
142
- connection = Excon.new('http://a.subdomain.noproxy2')
143
- connection.data[:proxy]
144
- end
145
- end
146
-
147
- env_restore
148
- end
149
-
150
- tests('with complete proxy config from the environment') do
151
- env = {
152
- 'http_proxy' => 'http://myproxy:8080',
153
- 'https_proxy' => 'http://mysecureproxy:8081',
154
- 'no_proxy' => 'noproxy, subdomain.noproxy2'
155
- }
156
- tests('lowercase') { env_proxy_tests(env) }
157
- upperenv = {}
158
- env.each do |k, v|
159
- upperenv[k.upcase] = v
160
- end
161
- tests('uppercase') { env_proxy_tests(upperenv) }
162
- end
163
-
164
- tests('with only http_proxy config from the environment') do
165
- env_init({'http_proxy' => 'http://myproxy:8080' })
166
-
167
- tests('an https connection') do
168
- connection = nil
169
-
170
- tests('connection.data[:proxy][:host]').returns('myproxy') do
171
- connection = Excon.new('https://secret.com')
172
- connection.data[:proxy][:host]
173
- end
174
-
175
- tests('connection.data[:proxy][:port]').returns(8080) do
176
- connection.data[:proxy][:port]
177
- end
178
-
179
- tests('connection.data[:proxy][:scheme]').returns('http') do
180
- connection.data[:proxy][:scheme]
181
- end
182
- end
183
-
184
- env_restore
185
- end
186
-
187
- tests('with a unix socket proxy config from the environment') do
188
- env_init({
189
- 'http_proxy' => 'unix:///tmp/myproxy.sock',
190
- })
191
-
192
- tests('an https connection') do
193
- connection = nil
194
-
195
- tests('connection.data[:proxy][:host]').returns(nil) do
196
- connection = Excon.new('https://secret.com')
197
- connection.data[:proxy][:host]
198
- end
199
-
200
- tests('connection.data[:proxy][:port]').returns(nil) do
201
- connection.data[:proxy][:port]
202
- end
203
-
204
- tests('connection.data[:proxy][:scheme]').returns('unix') do
205
- connection.data[:proxy][:scheme]
206
- end
207
-
208
- tests('connection.data[:proxy][:path]').returns('/tmp/myproxy.sock') do
209
- connection.data[:proxy][:path]
210
- end
211
- end
212
-
213
- env_restore
214
- end
215
-
216
- end
217
-
218
- with_rackup('proxy.ru') do
219
-
220
- tests('http proxying: http://foo.com:8080') do
221
- response = nil
222
-
223
- tests('response.status').returns(200) do
224
- connection = Excon.new('http://foo.com:8080', :proxy => 'http://127.0.0.1:9292')
225
- response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
226
-
227
- response.status
228
- end
229
-
230
- # must be absolute form for proxy requests
231
- tests('sent Request URI').returns('http://foo.com:8080/bar?alpha=kappa') do
232
- response.headers['Sent-Request-Uri']
233
- end
234
-
235
- tests('sent Sent-Host header').returns('foo.com:8080') do
236
- response.headers['Sent-Host']
237
- end
238
-
239
- tests('sent Proxy-Connection header').returns('Keep-Alive') do
240
- response.headers['Sent-Proxy-Connection']
241
- end
242
-
243
- tests('response.body (proxied content)').returns('proxied content') do
244
- response.body
245
- end
246
- end
247
-
248
- tests('http proxying: http://user:pass@foo.com:8080') do
249
- response = nil
250
-
251
- tests('response.status').returns(200) do
252
- connection = Excon.new('http://foo.com:8080', :proxy => 'http://user:pass@127.0.0.1:9292')
253
- response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
254
-
255
- response.status
256
- end
257
-
258
- # must be absolute form for proxy requests
259
- tests('sent Request URI').returns('http://foo.com:8080/bar?alpha=kappa') do
260
- response.headers['Sent-Request-Uri']
261
- end
262
-
263
- tests('sent Host header').returns('foo.com:8080') do
264
- response.headers['Sent-Host']
265
- end
266
-
267
- tests('sent Proxy-Connection header').returns('Keep-Alive') do
268
- response.headers['Sent-Proxy-Connection']
269
- end
270
-
271
- tests('response.body (proxied content)').returns('proxied content') do
272
- response.body
273
- end
274
- end
275
-
276
- end
277
-
278
- with_unicorn('proxy.ru', 'unix:///tmp/myproxy.sock') do
279
- pending if RUBY_PLATFORM == 'java' # need to find suitable server for jruby
280
-
281
- tests('http proxying over unix socket: http://foo.com:8080') do
282
- response = nil
283
-
284
- tests('response.status').returns(200) do
285
- connection = Excon.new('http://foo.com:8080', :proxy => 'unix:///tmp/myproxy.sock')
286
- response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
287
-
288
- response.status
289
- end
290
-
291
- tests('sent Sent-Host header').returns('foo.com:8080') do
292
- response.headers['Sent-Host']
293
- end
294
-
295
- tests('sent Proxy-Connection header').returns('Keep-Alive') do
296
- response.headers['Sent-Proxy-Connection']
297
- end
298
-
299
- tests('response.body (proxied content)').returns('proxied content') do
300
- response.body
301
- end
302
- end
303
- end
304
-
305
- env_restore
306
- end