excon 0.62.0 → 0.92.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +0 -1
  3. data/LICENSE.md +1 -1
  4. data/README.md +7 -6
  5. data/data/cacert.pem +1220 -1828
  6. data/excon.gemspec +19 -3
  7. data/lib/excon/connection.rb +216 -139
  8. data/lib/excon/constants.rb +38 -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 +5 -16
  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 +11 -4
  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 +59 -42
  25. data/lib/excon/ssl_socket.rb +37 -15
  26. data/lib/excon/test/plugin/server/exec.rb +5 -2
  27. data/lib/excon/test/plugin/server/puma.rb +4 -1
  28. data/lib/excon/test/plugin/server/unicorn.rb +5 -0
  29. data/lib/excon/test/plugin/server/webrick.rb +4 -1
  30. data/lib/excon/test/server.rb +1 -1
  31. data/lib/excon/unix_socket.rb +1 -0
  32. data/lib/excon/utils.rb +59 -5
  33. data/lib/excon/version.rb +1 -1
  34. data/lib/excon.rb +25 -17
  35. metadata +27 -98
  36. data/.document +0 -5
  37. data/.gitignore +0 -13
  38. data/.rspec +0 -3
  39. data/.travis.yml +0 -29
  40. data/Gemfile +0 -19
  41. data/Rakefile +0 -41
  42. data/benchmarks/class_vs_lambda.rb +0 -50
  43. data/benchmarks/concat_vs_insert.rb +0 -21
  44. data/benchmarks/concat_vs_interpolate.rb +0 -22
  45. data/benchmarks/cr_lf.rb +0 -21
  46. data/benchmarks/downcase-eq-eq_vs_casecmp.rb +0 -169
  47. data/benchmarks/excon.rb +0 -69
  48. data/benchmarks/excon_vs.rb +0 -165
  49. data/benchmarks/for_vs_array_each.rb +0 -27
  50. data/benchmarks/for_vs_hash_each.rb +0 -27
  51. data/benchmarks/has_key-vs-lookup.rb +0 -177
  52. data/benchmarks/headers_case_sensitivity.rb +0 -83
  53. data/benchmarks/headers_split_vs_match.rb +0 -34
  54. data/benchmarks/implicit_block-vs-explicit_block.rb +0 -98
  55. data/benchmarks/merging.rb +0 -21
  56. data/benchmarks/single_vs_double_quotes.rb +0 -21
  57. data/benchmarks/string_ranged_index.rb +0 -87
  58. data/benchmarks/strip_newline.rb +0 -115
  59. data/benchmarks/vs_stdlib.rb +0 -82
  60. data/changelog.txt +0 -1083
  61. data/spec/excon/error_spec.rb +0 -139
  62. data/spec/excon/test/server_spec.rb +0 -28
  63. data/spec/excon_spec.rb +0 -7
  64. data/spec/helpers/file_path_helpers.rb +0 -22
  65. data/spec/requests/basic_spec.rb +0 -40
  66. data/spec/requests/eof_requests_spec.rb +0 -36
  67. data/spec/requests/unix_socket_spec.rb +0 -46
  68. data/spec/spec_helper.rb +0 -24
  69. data/spec/support/shared_contexts/test_server_context.rb +0 -83
  70. data/spec/support/shared_examples/shared_example_for_clients.rb +0 -218
  71. data/spec/support/shared_examples/shared_example_for_streaming_clients.rb +0 -20
  72. data/spec/support/shared_examples/shared_example_for_test_servers.rb +0 -16
  73. data/tests/authorization_header_tests.rb +0 -29
  74. data/tests/bad_tests.rb +0 -47
  75. data/tests/basic_tests.rb +0 -351
  76. data/tests/batch_requests.rb +0 -133
  77. data/tests/complete_responses.rb +0 -31
  78. data/tests/data/127.0.0.1.cert.crt +0 -20
  79. data/tests/data/127.0.0.1.cert.key +0 -27
  80. data/tests/data/excon.cert.crt +0 -20
  81. data/tests/data/excon.cert.key +0 -27
  82. data/tests/data/xs +0 -1
  83. data/tests/error_tests.rb +0 -145
  84. data/tests/header_tests.rb +0 -119
  85. data/tests/middlewares/canned_response_tests.rb +0 -34
  86. data/tests/middlewares/capture_cookies_tests.rb +0 -34
  87. data/tests/middlewares/decompress_tests.rb +0 -157
  88. data/tests/middlewares/escape_path_tests.rb +0 -36
  89. data/tests/middlewares/idempotent_tests.rb +0 -206
  90. data/tests/middlewares/instrumentation_tests.rb +0 -315
  91. data/tests/middlewares/mock_tests.rb +0 -304
  92. data/tests/middlewares/redirect_follower_tests.rb +0 -112
  93. data/tests/pipeline_tests.rb +0 -40
  94. data/tests/proxy_tests.rb +0 -306
  95. data/tests/query_string_tests.rb +0 -87
  96. data/tests/rackups/basic.rb +0 -41
  97. data/tests/rackups/basic.ru +0 -3
  98. data/tests/rackups/basic_auth.ru +0 -14
  99. data/tests/rackups/deflater.ru +0 -4
  100. data/tests/rackups/proxy.ru +0 -18
  101. data/tests/rackups/query_string.ru +0 -13
  102. data/tests/rackups/redirecting.ru +0 -23
  103. data/tests/rackups/redirecting_with_cookie.ru +0 -40
  104. data/tests/rackups/request_headers.ru +0 -15
  105. data/tests/rackups/request_methods.ru +0 -21
  106. data/tests/rackups/response_header.ru +0 -18
  107. data/tests/rackups/ssl.ru +0 -16
  108. data/tests/rackups/ssl_mismatched_cn.ru +0 -15
  109. data/tests/rackups/ssl_verify_peer.ru +0 -16
  110. data/tests/rackups/streaming.ru +0 -30
  111. data/tests/rackups/thread_safety.ru +0 -17
  112. data/tests/rackups/timeout.ru +0 -14
  113. data/tests/rackups/webrick_patch.rb +0 -34
  114. data/tests/request_headers_tests.rb +0 -21
  115. data/tests/request_method_tests.rb +0 -47
  116. data/tests/request_tests.rb +0 -59
  117. data/tests/response_tests.rb +0 -197
  118. data/tests/servers/bad.rb +0 -20
  119. data/tests/servers/eof.rb +0 -17
  120. data/tests/servers/error.rb +0 -20
  121. data/tests/servers/good.rb +0 -350
  122. data/tests/test_helper.rb +0 -306
  123. data/tests/thread_safety_tests.rb +0 -39
  124. data/tests/timeout_tests.rb +0 -12
  125. data/tests/utils_tests.rb +0 -81
@@ -1,304 +0,0 @@
1
- Shindo.tests('Excon stubs') do
2
- env_init
3
-
4
- tests("missing stub").raises(Excon::Errors::StubNotFound) do
5
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
6
- connection.request(:method => :get, :path => '/content-length/100')
7
- end
8
-
9
- tests("stub({})").raises(ArgumentError) do
10
- Excon.stub({})
11
- end
12
-
13
- tests("stub({}, {}) {}").raises(ArgumentError) do
14
- Excon.stub({}, {}) {}
15
- end
16
-
17
- tests("stub({:method => :get}, {:body => 'body', :status => 200})") do
18
- connection = nil
19
- response = nil
20
-
21
- tests('response.body').returns('body') do
22
- Excon.stub({:method => :get}, {:body => 'body', :status => 200})
23
-
24
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
25
- response = connection.request(:method => :get, :path => '/content-length/100')
26
-
27
- response.body
28
- end
29
-
30
- tests('response.headers').returns({}) do
31
- response.headers
32
- end
33
-
34
- tests('response.status').returns(200) do
35
- response.status
36
- end
37
-
38
- tests('response_block yields body').returns('body') do
39
- body = ''
40
- response_block = lambda do |chunk, remaining_bytes, total_bytes|
41
- body << chunk
42
- end
43
- connection.request(:method => :get, :path => '/content-length/100', :response_block => response_block)
44
- body
45
- end
46
-
47
- tests('response.body empty with response_block').returns('') do
48
- response_block = lambda { |_, _, _| }
49
- connection.request(:method => :get, :path => '/content-length/100', :response_block => response_block).body
50
- end
51
-
52
- Excon.stubs.clear
53
-
54
- end
55
-
56
- tests("stub({:path => %r{/tests/(\S+)}}, {:body => $1, :status => 200})") do
57
- connection = nil
58
- response = nil
59
-
60
- tests('response.body').returns('test') do
61
- Excon.stub({:path => %r{/tests/(\S+)}}) do |params|
62
- {
63
- :body => params[:captures][:path].first,
64
- :status => 200
65
- }
66
- end
67
-
68
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
69
- response = connection.request(:method => :get, :path => '/tests/test')
70
-
71
- response.body
72
- end
73
-
74
- tests('response.headers').returns({}) do
75
- response.headers
76
- end
77
-
78
- tests('response.status').returns(200) do
79
- response.status
80
- end
81
-
82
- Excon.stubs.clear
83
-
84
- end
85
-
86
- tests("stub({:body => 'body', :method => :get}) {|params| {:body => params[:body], :headers => params[:headers], :status => 200}}") do
87
- connection = nil
88
- response = nil
89
-
90
- tests('response.body').returns('body') do
91
- Excon.stub({:body => 'body', :method => :get}) {|params| {:body => params[:body], :headers => params[:headers], :status => 200}}
92
-
93
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
94
- response = connection.request(:body => 'body', :method => :get, :path => '/content-length/100')
95
-
96
- response.body
97
- end
98
-
99
- tests('response.headers').returns({'Host' => '127.0.0.1:9292', 'User-Agent' => "excon/#{Excon::VERSION}"}) do
100
- response.headers
101
- end
102
-
103
- tests('response.status').returns(200) do
104
- response.status
105
- end
106
-
107
- tests('response_block yields body').returns('body') do
108
- body = ''
109
- response_block = lambda do |chunk, remaining_bytes, total_bytes|
110
- body << chunk
111
- end
112
- connection.request(:body => 'body', :method => :get, :path => '/content-length/100', :response_block => response_block)
113
- body
114
- end
115
-
116
- tests('response.body empty with response_block').returns('') do
117
- response_block = lambda { |_, _, _| }
118
- connection.request(:body => 'body', :method => :get, :path => '/content-length/100', :response_block => response_block).body
119
- end
120
-
121
- Excon.stubs.clear
122
-
123
- end
124
-
125
- tests("stub({:body => File.open(...), :method => :get}, { :status => 200 })") do
126
-
127
- tests('response.status').returns(200) do
128
- file_path = File.join(File.dirname(__FILE__), '..', 'data', 'xs')
129
-
130
- Excon.stub(
131
- { :body => File.read(file_path), :method => :get },
132
- { :status => 200 }
133
- )
134
-
135
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
136
- response = connection.request(:body => File.open(file_path), :method => :get, :path => '/')
137
-
138
- response.status
139
- end
140
-
141
- Excon.stubs.clear
142
-
143
- end
144
-
145
- tests("invalid stub response").raises(Excon::Errors::InvalidStub) do
146
- Excon.stub({:body => 42, :method => :get}, {:status => 200})
147
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
148
- connection.request(:body => 42, :method => :get, :path => '/').status
149
- end
150
-
151
- tests("mismatched stub").raises(Excon::Errors::StubNotFound) do
152
- Excon.stub({:method => :post}, {:body => 'body'})
153
- Excon.get('http://127.0.0.1:9292/', :mock => true)
154
- end
155
-
156
- with_server('good') do
157
- tests('allow mismatched stub').returns(200) do
158
- Excon.stub({:path => '/echo/request_count'}, {:body => 'body'})
159
- Excon.get(
160
- 'http://127.0.0.1:9292/echo/request',
161
- :mock => true,
162
- :allow_unstubbed_requests => true
163
- ).status
164
- end
165
- end
166
-
167
- Excon.stubs.clear
168
-
169
- tests("stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})") do
170
-
171
- test("response_block yields body") do
172
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
173
- Excon.stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})
174
-
175
- chunks = []
176
- response_block = lambda do |chunk, remaining_bytes, total_bytes|
177
- chunks << chunk
178
- end
179
- connection.request(:method => :get, :path => '/content-length/100', :response_block => response_block)
180
- chunks == ['x' * Excon::DEFAULT_CHUNK_SIZE, 'x']
181
- end
182
-
183
- tests("response.body empty with response_block").returns('') do
184
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
185
- Excon.stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})
186
- response_block = lambda { |_, _, _| }
187
- connection.request(:method => :get, :path => '/content-length/100', :response_block => response_block).body
188
- end
189
-
190
- end
191
-
192
- Excon.stubs.clear
193
-
194
- tests("stub({:url => 'https://user:pass@foo.bar.com:9999/baz?quux=true'}, {:status => 200})") do
195
- test("get(:expects => 200)") do
196
- Excon.stub({:url => 'https://user:pass@foo.bar.com:9999/baz?quux=true'}, {:status => 200})
197
- Excon.new("https://user:pass@foo.bar.com:9999/baz?quux=true", :mock => true).get(:expects => 200)
198
- true
199
- end
200
- end
201
-
202
- Excon.stubs.clear
203
-
204
- tests("stub({}, {:status => 404, :body => 'Not Found'}") do
205
- connection = nil
206
-
207
- tests("request(:expects => 200, :method => :get, :path => '/')").raises(Excon::Errors::NotFound) do
208
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
209
- Excon.stub({}, {:status => 404, :body => 'Not Found'})
210
-
211
- connection.request(:expects => 200, :method => :get, :path => '/')
212
- end
213
-
214
- tests("Expects exception should contain response object").returns(Excon::Response) do
215
- begin
216
- connection.request(:expects => 200, :method => :get, :path => '/')
217
- rescue Excon::Errors::NotFound => e
218
- e.response.class
219
- end
220
- end
221
-
222
- test("request(:expects => 200, :method => :get, :path => '/') with block does not invoke the block since it raises an error") do
223
- block_called = false
224
- begin
225
- response_block = lambda do |_,_,_|
226
- block_called = true
227
- end
228
- connection.request(:expects => 200, :method => :get, :path => '/', :response_block => response_block)
229
- rescue Excon::Errors::NotFound
230
- end
231
- !block_called
232
- end
233
-
234
- Excon.stubs.clear
235
-
236
- end
237
-
238
- tests("stub_for({})") do
239
- tests("stub_for({})").returns([{}, {}]) do
240
- Excon.new('http://127.0.0.1:9292', :mock => true)
241
- Excon.stub({}, {})
242
-
243
- Excon.stub_for({})
244
- end
245
-
246
- Excon.stubs.clear
247
- end
248
-
249
- tests("unstub({})") do
250
- connection = nil
251
-
252
- tests("unstub({})").returns([{}, {}]) do
253
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
254
- Excon.stub({}, {})
255
-
256
- Excon.unstub({})
257
- end
258
-
259
- tests("request(:method => :get)").raises(Excon::Errors::StubNotFound) do
260
- connection.request(:method => :get)
261
- end
262
-
263
- Excon.stubs.clear
264
- end
265
-
266
- tests("global stubs") do
267
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
268
- Excon.stub({}, {:body => '1'})
269
- t = Thread.new do
270
- Excon.stub({}, {:body => '2'})
271
- connection.request(:method => :get).body
272
- end
273
- tests("get on a different thread").returns('2') do
274
- t.join.value
275
- end
276
- tests("get on main thread").returns('2') do
277
- connection.request(:method => :get).body
278
- end
279
- Excon.stubs.clear
280
- end
281
-
282
- tests("thread-local stubs") do
283
- original_stubs_value = Excon.defaults[:stubs]
284
- Excon.defaults[:stubs] = :local
285
-
286
- connection = Excon.new('http://127.0.0.1:9292', :mock => true)
287
- Excon.stub({}, {:body => '1'})
288
- t = Thread.new do
289
- Excon.stub({}, {:body => '2'})
290
- connection.request(:method => :get).body
291
- end
292
- tests("get on a different thread").returns('2') do
293
- t.join.value
294
- end
295
- tests("get on main thread").returns('1') do
296
- connection.request(:method => :get).body
297
- end
298
- Excon.stubs.clear
299
-
300
- Excon.defaults[:stubs] = original_stubs_value
301
- end
302
-
303
- env_restore
304
- end
@@ -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