faraday 0.9.1 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +196 -0
- data/LICENSE.md +1 -1
- data/README.md +192 -28
- data/Rakefile +6 -64
- data/lib/faraday/adapter/em_http.rb +17 -11
- data/lib/faraday/adapter/em_http_ssl_patch.rb +1 -1
- data/lib/faraday/adapter/em_synchrony.rb +19 -5
- data/lib/faraday/adapter/excon.rb +13 -11
- data/lib/faraday/adapter/httpclient.rb +31 -9
- data/lib/faraday/adapter/net_http.rb +36 -14
- data/lib/faraday/adapter/net_http_persistent.rb +37 -17
- data/lib/faraday/adapter/patron.rb +44 -21
- data/lib/faraday/adapter/rack.rb +1 -1
- data/lib/faraday/adapter/test.rb +79 -28
- data/lib/faraday/adapter/typhoeus.rb +4 -115
- data/lib/faraday/adapter.rb +10 -1
- data/lib/faraday/autoload.rb +1 -1
- data/lib/faraday/connection.rb +72 -20
- data/lib/faraday/deprecate.rb +101 -0
- data/lib/faraday/error.rb +90 -24
- data/lib/faraday/options.rb +43 -20
- data/lib/faraday/parameters.rb +56 -39
- data/lib/faraday/rack_builder.rb +27 -2
- data/lib/faraday/request/authorization.rb +1 -2
- data/lib/faraday/request/multipart.rb +7 -2
- data/lib/faraday/request/retry.rb +84 -19
- data/lib/faraday/request.rb +22 -0
- data/lib/faraday/response/logger.rb +29 -8
- data/lib/faraday/response/raise_error.rb +7 -3
- data/lib/faraday/response.rb +9 -5
- data/lib/faraday/utils.rb +32 -3
- data/lib/faraday.rb +14 -34
- data/spec/faraday/deprecate_spec.rb +69 -0
- data/spec/faraday/error_spec.rb +102 -0
- data/spec/faraday/response/raise_error_spec.rb +95 -0
- data/spec/spec_helper.rb +104 -0
- data/test/adapters/em_http_test.rb +10 -0
- data/test/adapters/em_synchrony_test.rb +22 -10
- data/test/adapters/excon_test.rb +10 -0
- data/test/adapters/httpclient_test.rb +14 -1
- data/test/adapters/integration.rb +17 -8
- data/test/adapters/logger_test.rb +65 -11
- data/test/adapters/net_http_persistent_test.rb +96 -2
- data/test/adapters/net_http_test.rb +67 -2
- data/test/adapters/patron_test.rb +28 -8
- data/test/adapters/rack_test.rb +8 -1
- data/test/adapters/test_middleware_test.rb +46 -3
- data/test/adapters/typhoeus_test.rb +19 -9
- data/test/composite_read_io_test.rb +16 -18
- data/test/connection_test.rb +294 -78
- data/test/env_test.rb +55 -5
- data/test/helper.rb +11 -17
- data/test/middleware/retry_test.rb +115 -10
- data/test/middleware_stack_test.rb +97 -10
- data/test/options_test.rb +97 -16
- data/test/parameters_test.rb +94 -1
- data/test/request_middleware_test.rb +24 -40
- data/test/response_middleware_test.rb +4 -4
- data/test/utils_test.rb +40 -0
- metadata +21 -66
- data/.document +0 -6
- data/CONTRIBUTING.md +0 -36
- data/Gemfile +0 -25
- data/faraday.gemspec +0 -34
- data/script/cached-bundle +0 -46
- data/script/console +0 -7
- data/script/generate_certs +0 -42
- data/script/package +0 -7
- data/script/proxy-server +0 -42
- data/script/release +0 -17
- data/script/s3-put +0 -71
- data/script/server +0 -36
- data/script/test +0 -172
@@ -4,11 +4,32 @@ module Adapters
|
|
4
4
|
class TestMiddleware < Faraday::TestCase
|
5
5
|
Stubs = Faraday::Adapter.lookup_middleware(:test)::Stubs
|
6
6
|
def setup
|
7
|
-
@stubs = Stubs.new
|
7
|
+
@stubs = Stubs.new do |stub|
|
8
|
+
stub.get('/hello') do
|
9
|
+
[200, {'Content-Type' => 'text/html'}, 'hello']
|
10
|
+
end
|
11
|
+
stub.get('/method-echo') do |env|
|
12
|
+
[200, {'Content-Type' => 'text/html'}, env[:method].to_s]
|
13
|
+
end
|
14
|
+
stub.get(/\A\/resources\/\d+(?:\?|\z)/) do
|
15
|
+
[200, {'Content-Type' => 'text/html'}, 'show']
|
16
|
+
end
|
17
|
+
stub.get(/\A\/resources\/(specified)\z/) do |env, meta|
|
18
|
+
[200, {'Content-Type' => 'text/html'}, "show #{meta[:match_data][1]}"]
|
19
|
+
end
|
20
|
+
stub.get('http://domain.test/hello') do
|
21
|
+
[200, {'Content-Type' => 'text/html'}, 'domain: hello']
|
22
|
+
end
|
23
|
+
stub.get('http://wrong.test/hello') do
|
24
|
+
[200, {'Content-Type' => 'text/html'}, 'wrong: hello']
|
25
|
+
end
|
26
|
+
stub.get('http://wrong.test/bait') do
|
27
|
+
[404, {'Content-Type' => 'text/html'}]
|
28
|
+
end
|
29
|
+
end
|
8
30
|
@conn = Faraday.new do |builder|
|
9
31
|
builder.adapter :test, @stubs
|
10
32
|
end
|
11
|
-
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
|
12
33
|
@resp = @conn.get('/hello')
|
13
34
|
end
|
14
35
|
|
@@ -24,8 +45,24 @@ module Adapters
|
|
24
45
|
assert_equal 'hello', @resp.body
|
25
46
|
end
|
26
47
|
|
48
|
+
def test_middleware_with_host_points_to_the_right_stub
|
49
|
+
assert_equal 'domain: hello', @conn.get('http://domain.test/hello').body
|
50
|
+
end
|
51
|
+
|
27
52
|
def test_middleware_can_be_called_several_times
|
28
|
-
assert_equal 'hello', @conn.get(
|
53
|
+
assert_equal 'hello', @conn.get('/hello').body
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_middleware_can_handle_regular_expression_path
|
57
|
+
assert_equal 'show', @conn.get('/resources/1').body
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_middleware_can_handle_single_parameter_block
|
61
|
+
assert_equal 'get', @conn.get('/method-echo').body
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_middleware_can_handle_regular_expression_path_with_captured_result
|
65
|
+
assert_equal 'show specified', @conn.get('/resources/specified').body
|
29
66
|
end
|
30
67
|
|
31
68
|
def test_middleware_with_get_params
|
@@ -104,6 +141,12 @@ module Adapters
|
|
104
141
|
end
|
105
142
|
end
|
106
143
|
|
144
|
+
def test_raises_an_error_if_no_stub_is_found_for_specified_host
|
145
|
+
assert_raises Stubs::NotFound do
|
146
|
+
@conn.get('http://domain.test/bait')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
107
150
|
def test_raises_an_error_if_no_stub_is_found_for_request_without_this_header
|
108
151
|
@stubs.get('/yo', { 'X-HELLO' => 'hello' }) { [200, {}, 'a'] }
|
109
152
|
assert_raises Faraday::Adapter::Test::Stubs::NotFound do
|
@@ -6,23 +6,33 @@ module Adapters
|
|
6
6
|
def adapter() :typhoeus end
|
7
7
|
|
8
8
|
Integration.apply(self, :Parallel) do
|
9
|
-
# https://github.com/dbalatero/typhoeus/issues/75
|
10
|
-
undef :test_GET_with_body
|
11
|
-
|
12
|
-
# Not a Typhoeus bug, but WEBrick inability to handle "100-continue"
|
13
|
-
# which libcurl seems to generate for this particular request:
|
14
|
-
undef :test_POST_sends_files
|
15
|
-
|
16
9
|
# inconsistent outcomes ranging from successful response to connection error
|
17
10
|
undef :test_proxy_auth_fail if ssl_mode?
|
18
11
|
|
12
|
+
# Typhoeus adapter not supporting Faraday::SSLError
|
13
|
+
undef :test_GET_ssl_fails_with_bad_cert if ssl_mode?
|
14
|
+
|
19
15
|
def test_binds_local_socket
|
20
16
|
host = '1.2.3.4'
|
21
17
|
conn = create_connection :request => { :bind => { :host => host } }
|
22
18
|
assert_equal host, conn.options[:bind][:host]
|
23
19
|
end
|
24
20
|
|
25
|
-
|
21
|
+
# Typhoeus::Response doesn't provide an easy way to access the reason phrase,
|
22
|
+
# so override the shared test from Common.
|
23
|
+
def test_GET_reason_phrase
|
24
|
+
response = get('echo')
|
25
|
+
assert_nil response.reason_phrase
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_custom_adapter_config
|
30
|
+
adapter = Faraday::Adapter::Typhoeus.new(nil, { :forbid_reuse => true, :maxredirs => 1 })
|
31
|
+
|
32
|
+
request = adapter.method(:typhoeus_request).call({})
|
33
|
+
|
34
|
+
assert_equal true, request.options[:forbid_reuse]
|
35
|
+
assert_equal 1, request.options[:maxredirs]
|
36
|
+
end
|
26
37
|
end
|
27
38
|
end
|
28
|
-
|
@@ -40,22 +40,22 @@ class CompositeReadIOTest < Faraday::TestCase
|
|
40
40
|
assert_equal "abc", io.read(3)
|
41
41
|
assert_equal "d12", io.read(3)
|
42
42
|
assert_equal "34", io.read(3)
|
43
|
-
|
44
|
-
|
43
|
+
assert_nil io.read(3)
|
44
|
+
assert_nil io.read(3)
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_multipart_read_limited_size_larger_than_part
|
48
48
|
io = composite_io(part("abcd"), part("1234"))
|
49
49
|
assert_equal "abcd12", io.read(6)
|
50
50
|
assert_equal "34", io.read(6)
|
51
|
-
|
51
|
+
assert_nil io.read(6)
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_multipart_read_with_blank_parts
|
55
55
|
io = composite_io(part(""), part("abcd"), part(""), part("1234"), part(""))
|
56
56
|
assert_equal "abcd12", io.read(6)
|
57
57
|
assert_equal "34", io.read(6)
|
58
|
-
|
58
|
+
assert_nil io.read(6)
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_multipart_rewind
|
@@ -65,7 +65,7 @@ class CompositeReadIOTest < Faraday::TestCase
|
|
65
65
|
io.rewind
|
66
66
|
assert_equal "abc", io.read(3)
|
67
67
|
assert_equal "d1234", io.read(5)
|
68
|
-
|
68
|
+
assert_nil io.read(3)
|
69
69
|
io.rewind
|
70
70
|
assert_equal "ab", io.read(2)
|
71
71
|
end
|
@@ -86,21 +86,19 @@ class CompositeReadIOTest < Faraday::TestCase
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
assert_equal bin("\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n"), io.read
|
94
|
-
end
|
89
|
+
def test_read_from_multibyte
|
90
|
+
File.open(File.dirname(__FILE__) + '/multibyte.txt') do |utf8|
|
91
|
+
io = composite_io(part("\x86"), Part.new(utf8))
|
92
|
+
assert_equal bin("\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n"), io.read
|
95
93
|
end
|
94
|
+
end
|
96
95
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
96
|
+
def test_limited_from_multibyte
|
97
|
+
File.open(File.dirname(__FILE__) + '/multibyte.txt') do |utf8|
|
98
|
+
io = composite_io(part("\x86"), Part.new(utf8))
|
99
|
+
assert_equal bin("\x86\xE3\x83"), io.read(3)
|
100
|
+
assert_equal bin("\x95\xE3\x82"), io.read(3)
|
101
|
+
assert_equal bin("\xA1\xE3\x82\xA4\xE3\x83\xAB\n"), io.read(8)
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|