faraday 0.9.0 → 0.9.2

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 (61) hide show
  1. data/LICENSE.md +1 -1
  2. data/README.md +52 -23
  3. data/lib/faraday.rb +1 -1
  4. data/lib/faraday/adapter/em_synchrony.rb +8 -0
  5. data/lib/faraday/adapter/excon.rb +1 -0
  6. data/lib/faraday/adapter/httpclient.rb +14 -3
  7. data/lib/faraday/adapter/net_http.rb +26 -20
  8. data/lib/faraday/adapter/net_http_persistent.rb +5 -3
  9. data/lib/faraday/adapter/patron.rb +13 -3
  10. data/lib/faraday/autoload.rb +0 -1
  11. data/lib/faraday/connection.rb +8 -3
  12. data/lib/faraday/options.rb +9 -0
  13. data/lib/faraday/parameters.rb +62 -58
  14. data/lib/faraday/rack_builder.rb +3 -2
  15. data/lib/faraday/request/retry.rb +40 -4
  16. data/lib/faraday/response.rb +2 -2
  17. data/lib/faraday/response/logger.rb +26 -1
  18. data/lib/faraday/utils.rb +13 -1
  19. metadata +61 -120
  20. checksums.yaml +0 -7
  21. data/.document +0 -6
  22. data/CHANGELOG.md +0 -15
  23. data/CONTRIBUTING.md +0 -36
  24. data/Gemfile +0 -29
  25. data/Rakefile +0 -71
  26. data/faraday.gemspec +0 -34
  27. data/script/console +0 -7
  28. data/script/generate_certs +0 -42
  29. data/script/package +0 -7
  30. data/script/proxy-server +0 -42
  31. data/script/release +0 -17
  32. data/script/server +0 -36
  33. data/script/test +0 -172
  34. data/test/adapters/default_test.rb +0 -14
  35. data/test/adapters/em_http_test.rb +0 -20
  36. data/test/adapters/em_synchrony_test.rb +0 -20
  37. data/test/adapters/excon_test.rb +0 -20
  38. data/test/adapters/httpclient_test.rb +0 -21
  39. data/test/adapters/integration.rb +0 -254
  40. data/test/adapters/logger_test.rb +0 -37
  41. data/test/adapters/net_http_persistent_test.rb +0 -20
  42. data/test/adapters/net_http_test.rb +0 -14
  43. data/test/adapters/patron_test.rb +0 -20
  44. data/test/adapters/rack_test.rb +0 -31
  45. data/test/adapters/test_middleware_test.rb +0 -114
  46. data/test/adapters/typhoeus_test.rb +0 -28
  47. data/test/authentication_middleware_test.rb +0 -65
  48. data/test/composite_read_io_test.rb +0 -111
  49. data/test/connection_test.rb +0 -522
  50. data/test/env_test.rb +0 -210
  51. data/test/helper.rb +0 -81
  52. data/test/live_server.rb +0 -67
  53. data/test/middleware/instrumentation_test.rb +0 -88
  54. data/test/middleware/retry_test.rb +0 -109
  55. data/test/middleware_stack_test.rb +0 -173
  56. data/test/multibyte.txt +0 -1
  57. data/test/options_test.rb +0 -252
  58. data/test/request_middleware_test.rb +0 -142
  59. data/test/response_middleware_test.rb +0 -72
  60. data/test/strawberry.rb +0 -2
  61. data/test/utils_test.rb +0 -58
@@ -1,14 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class DefaultTest < Faraday::TestCase
5
-
6
- def adapter() :default end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- # default stack is not configured with Multipart
10
- undef :test_POST_sends_files
11
- end
12
-
13
- end
14
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class EMHttpTest < Faraday::TestCase
5
-
6
- def adapter() :em_http end
7
-
8
- Integration.apply(self, :Parallel) do
9
- # https://github.com/eventmachine/eventmachine/pull/289
10
- undef :test_timeout
11
-
12
- def test_binds_local_socket
13
- host = '1.2.3.4'
14
- conn = create_connection :request => { :bind => { :host => host } }
15
- assert_equal host, conn.options[:bind][:host]
16
- end
17
- end unless jruby? and ssl_mode?
18
- # https://github.com/eventmachine/eventmachine/issues/180
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class EMSynchronyTest < Faraday::TestCase
5
-
6
- def adapter() :em_synchrony end
7
-
8
- Integration.apply(self, :Parallel) do
9
- # https://github.com/eventmachine/eventmachine/pull/289
10
- undef :test_timeout
11
-
12
- def test_binds_local_socket
13
- host = '1.2.3.4'
14
- conn = create_connection :request => { :bind => { :host => host } }
15
- #put conn.get('/who-am-i').body
16
- assert_equal host, conn.options[:bind][:host]
17
- end
18
- end unless RUBY_VERSION < '1.9' or jruby?
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class ExconTest < Faraday::TestCase
5
-
6
- def adapter() :excon end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- # https://github.com/geemus/excon/issues/126 ?
10
- undef :test_timeout if ssl_mode?
11
-
12
- # Excon lets OpenSSL::SSL::SSLError be raised without any way to
13
- # distinguish whether it happened because of a 407 proxy response
14
- undef :test_proxy_auth_fail if ssl_mode?
15
-
16
- # https://github.com/geemus/excon/issues/358
17
- undef :test_connection_error if RUBY_VERSION >= '2.1.0'
18
- end
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class HttpclientTest < Faraday::TestCase
5
-
6
- def adapter() :httpclient end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- def setup
10
- require 'httpclient' unless defined?(HTTPClient)
11
- HTTPClient::NO_PROXY_HOSTS.delete('localhost')
12
- end
13
-
14
- def test_binds_local_socket
15
- host = '1.2.3.4'
16
- conn = create_connection :request => { :bind => { :host => host } }
17
- assert_equal host, conn.options[:bind][:host]
18
- end
19
- end
20
- end
21
- end
@@ -1,254 +0,0 @@
1
- require 'forwardable'
2
- require File.expand_path("../../helper", __FILE__)
3
- Faraday.require_lib 'autoload'
4
-
5
- module Adapters
6
- # Adapter integration tests. To use, implement two methods:
7
- #
8
- # `#adapter` required. returns a symbol for the adapter middleware name
9
- # `#adapter_options` optional. extra arguments for building an adapter
10
- module Integration
11
- def self.apply(base, *extra_features)
12
- if base.live_server?
13
- features = [:Common]
14
- features.concat extra_features
15
- features << :SSL if base.ssl_mode?
16
- features.each {|name| base.send(:include, self.const_get(name)) }
17
- yield if block_given?
18
- elsif !defined? @warned
19
- warn "Warning: Not running integration tests against a live server."
20
- warn "Start the server `ruby test/live_server.rb` and set the LIVE=1 env variable."
21
- @warned = true
22
- end
23
- end
24
-
25
- module Parallel
26
- def test_in_parallel
27
- resp1, resp2 = nil, nil
28
-
29
- connection = create_connection
30
- connection.in_parallel do
31
- resp1 = connection.get('echo?a=1')
32
- resp2 = connection.get('echo?b=2')
33
- assert connection.in_parallel?
34
- assert_nil resp1.body
35
- assert_nil resp2.body
36
- end
37
- assert !connection.in_parallel?
38
- assert_equal 'get ?{"a"=>"1"}', resp1.body
39
- assert_equal 'get ?{"b"=>"2"}', resp2.body
40
- end
41
- end
42
-
43
- module NonParallel
44
- def test_no_parallel_support
45
- connection = create_connection
46
- response = nil
47
-
48
- err = capture_warnings do
49
- connection.in_parallel do
50
- response = connection.get('echo').body
51
- end
52
- end
53
- assert response
54
- assert_match "no parallel-capable adapter on Faraday stack", err
55
- assert_match __FILE__, err
56
- end
57
- end
58
-
59
- module Compression
60
- def test_GET_handles_compression
61
- res = get('echo_header', :name => 'accept-encoding')
62
- assert_match(/gzip;.+\bdeflate\b/, res.body)
63
- end
64
- end
65
-
66
- module SSL
67
- def test_GET_ssl_fails_with_bad_cert
68
- ca_file = 'tmp/faraday-different-ca-cert.crt'
69
- conn = create_connection(:ssl => {:ca_file => ca_file})
70
- err = assert_raises Faraday::SSLError do
71
- conn.get('/ssl')
72
- end
73
- assert_includes err.message, "certificate"
74
- end
75
- end
76
-
77
- module Common
78
- extend Forwardable
79
- def_delegators :create_connection, :get, :head, :put, :post, :patch, :delete, :run_request
80
-
81
- def test_GET_retrieves_the_response_body
82
- assert_equal 'get', get('echo').body
83
- end
84
-
85
- def test_GET_send_url_encoded_params
86
- assert_equal %(get ?{"name"=>"zack"}), get('echo', :name => 'zack').body
87
- end
88
-
89
- def test_GET_retrieves_the_response_headers
90
- response = get('echo')
91
- assert_match(/text\/plain/, response.headers['Content-Type'], 'original case fail')
92
- assert_match(/text\/plain/, response.headers['content-type'], 'lowercase fail')
93
- end
94
-
95
- def test_GET_handles_headers_with_multiple_values
96
- assert_equal 'one, two', get('multi').headers['set-cookie']
97
- end
98
-
99
- def test_GET_with_body
100
- response = get('echo') do |req|
101
- req.body = {'bodyrock' => true}
102
- end
103
- assert_equal %(get {"bodyrock"=>"true"}), response.body
104
- end
105
-
106
- def test_GET_sends_user_agent
107
- response = get('echo_header', {:name => 'user-agent'}, :user_agent => 'Agent Faraday')
108
- assert_equal 'Agent Faraday', response.body
109
- end
110
-
111
- def test_GET_ssl
112
- expected = self.class.ssl_mode?.to_s
113
- assert_equal expected, get('ssl').body
114
- end
115
-
116
- def test_POST_send_url_encoded_params
117
- assert_equal %(post {"name"=>"zack"}), post('echo', :name => 'zack').body
118
- end
119
-
120
- def test_POST_send_url_encoded_nested_params
121
- resp = post('echo', 'name' => {'first' => 'zack'})
122
- assert_equal %(post {"name"=>{"first"=>"zack"}}), resp.body
123
- end
124
-
125
- def test_POST_retrieves_the_response_headers
126
- assert_match(/text\/plain/, post('echo').headers['content-type'])
127
- end
128
-
129
- def test_POST_sends_files
130
- resp = post('file') do |req|
131
- req.body = {'uploaded_file' => Faraday::UploadIO.new(__FILE__, 'text/x-ruby')}
132
- end
133
- assert_equal "file integration.rb text/x-ruby #{File.size(__FILE__)}", resp.body
134
- end
135
-
136
- def test_PUT_send_url_encoded_params
137
- assert_equal %(put {"name"=>"zack"}), put('echo', :name => 'zack').body
138
- end
139
-
140
- def test_PUT_send_url_encoded_nested_params
141
- resp = put('echo', 'name' => {'first' => 'zack'})
142
- assert_equal %(put {"name"=>{"first"=>"zack"}}), resp.body
143
- end
144
-
145
- def test_PUT_retrieves_the_response_headers
146
- assert_match(/text\/plain/, put('echo').headers['content-type'])
147
- end
148
-
149
- def test_PATCH_send_url_encoded_params
150
- assert_equal %(patch {"name"=>"zack"}), patch('echo', :name => 'zack').body
151
- end
152
-
153
- def test_OPTIONS
154
- resp = run_request(:options, 'echo', nil, {})
155
- assert_equal 'options', resp.body
156
- end
157
-
158
- def test_HEAD_retrieves_no_response_body
159
- assert_equal '', head('echo').body
160
- end
161
-
162
- def test_HEAD_retrieves_the_response_headers
163
- assert_match(/text\/plain/, head('echo').headers['content-type'])
164
- end
165
-
166
- def test_DELETE_retrieves_the_response_headers
167
- assert_match(/text\/plain/, delete('echo').headers['content-type'])
168
- end
169
-
170
- def test_DELETE_retrieves_the_body
171
- assert_equal %(delete), delete('echo').body
172
- end
173
-
174
- def test_timeout
175
- conn = create_connection(:request => {:timeout => 1, :open_timeout => 1})
176
- assert_raises Faraday::Error::TimeoutError do
177
- conn.get '/slow'
178
- end
179
- end
180
-
181
- def test_connection_error
182
- assert_raises Faraday::Error::ConnectionFailed do
183
- get 'http://localhost:4'
184
- end
185
- end
186
-
187
- def test_proxy
188
- proxy_uri = URI(ENV['LIVE_PROXY'])
189
- conn = create_connection(:proxy => proxy_uri)
190
-
191
- res = conn.get '/echo'
192
- assert_equal 'get', res.body
193
-
194
- unless self.class.ssl_mode?
195
- # proxy can't append "Via" header for HTTPS responses
196
- assert_match(/:#{proxy_uri.port}$/, res['via'])
197
- end
198
- end
199
-
200
- def test_proxy_auth_fail
201
- proxy_uri = URI(ENV['LIVE_PROXY'])
202
- proxy_uri.password = 'WRONG'
203
- conn = create_connection(:proxy => proxy_uri)
204
-
205
- err = assert_raises Faraday::Error::ConnectionFailed do
206
- conn.get '/echo'
207
- end
208
-
209
- unless self.class.ssl_mode? && self.class.jruby?
210
- # JRuby raises "End of file reached" which cannot be distinguished from a 407
211
- assert_equal %{407 "Proxy Authentication Required "}, err.message
212
- end
213
- end
214
-
215
- def test_empty_body_response_represented_as_blank_string
216
- response = get('204')
217
- assert_equal '', response.body
218
- end
219
-
220
- def adapter
221
- raise NotImplementedError.new("Need to override #adapter")
222
- end
223
-
224
- # extra options to pass when building the adapter
225
- def adapter_options
226
- []
227
- end
228
-
229
- def create_connection(options = {})
230
- if adapter == :default
231
- builder_block = nil
232
- else
233
- builder_block = Proc.new do |b|
234
- b.request :multipart
235
- b.request :url_encoded
236
- b.adapter adapter, *adapter_options
237
- end
238
- end
239
-
240
- server = self.class.live_server
241
- url = '%s://%s:%d' % [server.scheme, server.host, server.port]
242
-
243
- options[:ssl] ||= {}
244
- options[:ssl][:ca_file] ||= ENV['SSL_FILE']
245
-
246
- Faraday::Connection.new(url, options, &builder_block).tap do |conn|
247
- conn.headers['X-Faraday-Adapter'] = adapter.to_s
248
- adapter_handler = conn.builder.handlers.last
249
- conn.builder.insert_before adapter_handler, Faraday::Response::RaiseError
250
- end
251
- end
252
- end
253
- end
254
- end
@@ -1,37 +0,0 @@
1
- require File.expand_path('../../helper', __FILE__)
2
- require 'stringio'
3
- require 'logger'
4
-
5
- module Adapters
6
- class LoggerTest < Faraday::TestCase
7
- def setup
8
- @io = StringIO.new
9
- @logger = Logger.new(@io)
10
- @logger.level = Logger::DEBUG
11
-
12
- @conn = Faraday.new do |b|
13
- b.response :logger, @logger
14
- b.adapter :test do |stubs|
15
- stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
16
- end
17
- end
18
- @resp = @conn.get '/hello', nil, :accept => 'text/html'
19
- end
20
-
21
- def test_still_returns_output
22
- assert_equal 'hello', @resp.body
23
- end
24
-
25
- def test_logs_method_and_url
26
- assert_match "get http:/hello", @io.string
27
- end
28
-
29
- def test_logs_request_headers
30
- assert_match %(Accept: "text/html), @io.string
31
- end
32
-
33
- def test_logs_response_headers
34
- assert_match %(Content-Type: "text/html), @io.string
35
- end
36
- end
37
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class NetHttpPersistentTest < Faraday::TestCase
5
-
6
- def adapter() :net_http_persistent end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- def setup
10
- if defined?(Net::HTTP::Persistent)
11
- # work around problems with mixed SSL certificates
12
- # https://github.com/drbrain/net-http-persistent/issues/45
13
- http = Net::HTTP::Persistent.new('Faraday')
14
- http.ssl_cleanup(4)
15
- end
16
- end if ssl_mode?
17
- end
18
-
19
- end
20
- end
@@ -1,14 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class NetHttpTest < Faraday::TestCase
5
-
6
- def adapter() :net_http end
7
-
8
- behaviors = [:NonParallel]
9
- behaviors << :Compression if RUBY_VERSION >= '1.9'
10
-
11
- Integration.apply(self, *behaviors)
12
-
13
- end
14
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class Patron < Faraday::TestCase
5
-
6
- def adapter() :patron end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- # https://github.com/toland/patron/issues/34
10
- undef :test_PATCH_send_url_encoded_params
11
-
12
- # https://github.com/toland/patron/issues/52
13
- undef :test_GET_with_body
14
-
15
- # no support for SSL peer verification
16
- undef :test_GET_ssl_fails_with_bad_cert if ssl_mode?
17
- end unless jruby?
18
-
19
- end
20
- end