faraday 0.9.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.md +1 -1
- data/README.md +189 -28
- data/lib/faraday/adapter/em_http.rb +8 -2
- data/lib/faraday/adapter/em_http_ssl_patch.rb +1 -1
- data/lib/faraday/adapter/em_synchrony.rb +16 -2
- data/lib/faraday/adapter/excon.rb +7 -8
- data/lib/faraday/adapter/httpclient.rb +27 -5
- data/lib/faraday/adapter/net_http.rb +16 -9
- data/lib/faraday/adapter/net_http_persistent.rb +24 -9
- data/lib/faraday/adapter/patron.rb +40 -12
- 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/error.rb +18 -5
- data/lib/faraday/options.rb +40 -18
- data/lib/faraday/parameters.rb +54 -38
- 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 +80 -17
- data/lib/faraday/request.rb +2 -0
- data/lib/faraday/response/logger.rb +28 -7
- data/lib/faraday/response.rb +6 -2
- data/lib/faraday/utils.rb +32 -3
- data/lib/faraday.rb +14 -34
- metadata +7 -93
- data/.document +0 -6
- data/CHANGELOG.md +0 -20
- data/CONTRIBUTING.md +0 -36
- data/Gemfile +0 -25
- data/Rakefile +0 -71
- 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
- data/test/adapters/default_test.rb +0 -14
- data/test/adapters/em_http_test.rb +0 -20
- data/test/adapters/em_synchrony_test.rb +0 -20
- data/test/adapters/excon_test.rb +0 -20
- data/test/adapters/httpclient_test.rb +0 -21
- data/test/adapters/integration.rb +0 -254
- data/test/adapters/logger_test.rb +0 -82
- data/test/adapters/net_http_persistent_test.rb +0 -20
- data/test/adapters/net_http_test.rb +0 -14
- data/test/adapters/patron_test.rb +0 -20
- data/test/adapters/rack_test.rb +0 -31
- data/test/adapters/test_middleware_test.rb +0 -114
- data/test/adapters/typhoeus_test.rb +0 -28
- data/test/authentication_middleware_test.rb +0 -65
- data/test/composite_read_io_test.rb +0 -111
- data/test/connection_test.rb +0 -522
- data/test/env_test.rb +0 -218
- data/test/helper.rb +0 -81
- data/test/live_server.rb +0 -67
- data/test/middleware/instrumentation_test.rb +0 -88
- data/test/middleware/retry_test.rb +0 -177
- data/test/middleware_stack_test.rb +0 -173
- data/test/multibyte.txt +0 -1
- data/test/options_test.rb +0 -252
- data/test/parameters_test.rb +0 -64
- data/test/request_middleware_test.rb +0 -142
- data/test/response_middleware_test.rb +0 -72
- data/test/strawberry.rb +0 -2
- data/test/utils_test.rb +0 -58
@@ -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
|
data/test/adapters/rack_test.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.expand_path("../integration", __FILE__)
|
2
|
-
require File.expand_path('../../live_server', __FILE__)
|
3
|
-
|
4
|
-
module Adapters
|
5
|
-
class RackTest < Faraday::TestCase
|
6
|
-
|
7
|
-
def adapter() :rack end
|
8
|
-
|
9
|
-
def adapter_options
|
10
|
-
[Faraday::LiveServer]
|
11
|
-
end
|
12
|
-
|
13
|
-
# no Integration.apply because this doesn't require a server as a separate process
|
14
|
-
include Integration::Common
|
15
|
-
include Integration::NonParallel
|
16
|
-
|
17
|
-
# not using shared test because error is swallowed by Sinatra
|
18
|
-
def test_timeout
|
19
|
-
conn = create_connection(:request => {:timeout => 1, :open_timeout => 1})
|
20
|
-
begin
|
21
|
-
conn.get '/slow'
|
22
|
-
rescue Faraday::Error::ClientError
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# test not applicable
|
27
|
-
undef test_connection_error
|
28
|
-
undef test_proxy
|
29
|
-
undef test_proxy_auth_fail
|
30
|
-
end
|
31
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require File.expand_path('../../helper', __FILE__)
|
2
|
-
|
3
|
-
module Adapters
|
4
|
-
class TestMiddleware < Faraday::TestCase
|
5
|
-
Stubs = Faraday::Adapter.lookup_middleware(:test)::Stubs
|
6
|
-
def setup
|
7
|
-
@stubs = Stubs.new
|
8
|
-
@conn = Faraday.new do |builder|
|
9
|
-
builder.adapter :test, @stubs
|
10
|
-
end
|
11
|
-
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
|
12
|
-
@resp = @conn.get('/hello')
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_middleware_with_simple_path_sets_status
|
16
|
-
assert_equal 200, @resp.status
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_middleware_with_simple_path_sets_headers
|
20
|
-
assert_equal 'text/html', @resp.headers['Content-Type']
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_middleware_with_simple_path_sets_body
|
24
|
-
assert_equal 'hello', @resp.body
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_middleware_can_be_called_several_times
|
28
|
-
assert_equal 'hello', @conn.get("/hello").body
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_middleware_with_get_params
|
32
|
-
@stubs.get('/param?a=1') { [200, {}, 'a'] }
|
33
|
-
assert_equal 'a', @conn.get('/param?a=1').body
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_middleware_ignores_unspecified_get_params
|
37
|
-
@stubs.get('/optional?a=1') { [200, {}, 'a'] }
|
38
|
-
assert_equal 'a', @conn.get('/optional?a=1&b=1').body
|
39
|
-
assert_equal 'a', @conn.get('/optional?a=1').body
|
40
|
-
assert_raises Faraday::Adapter::Test::Stubs::NotFound do
|
41
|
-
@conn.get('/optional')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_middleware_with_http_headers
|
46
|
-
@stubs.get('/yo', { 'X-HELLO' => 'hello' }) { [200, {}, 'a'] }
|
47
|
-
@stubs.get('/yo') { [200, {}, 'b'] }
|
48
|
-
assert_equal 'a', @conn.get('/yo') { |env| env.headers['X-HELLO'] = 'hello' }.body
|
49
|
-
assert_equal 'b', @conn.get('/yo').body
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_middleware_allow_different_outcomes_for_the_same_request
|
53
|
-
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
|
54
|
-
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'world'] }
|
55
|
-
assert_equal 'hello', @conn.get("/hello").body
|
56
|
-
assert_equal 'world', @conn.get("/hello").body
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_yields_env_to_stubs
|
60
|
-
@stubs.get '/hello' do |env|
|
61
|
-
assert_equal '/hello', env[:url].path
|
62
|
-
assert_equal 'foo.com', env[:url].host
|
63
|
-
assert_equal '1', env[:params]['a']
|
64
|
-
assert_equal 'text/plain', env[:request_headers]['Accept']
|
65
|
-
[200, {}, 'a']
|
66
|
-
end
|
67
|
-
|
68
|
-
@conn.headers['Accept'] = 'text/plain'
|
69
|
-
assert_equal 'a', @conn.get('http://foo.com/hello?a=1').body
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_parses_params_with_default_encoder
|
73
|
-
@stubs.get '/hello' do |env|
|
74
|
-
assert_equal '1', env[:params]['a']['b']
|
75
|
-
[200, {}, 'a']
|
76
|
-
end
|
77
|
-
|
78
|
-
assert_equal 'a', @conn.get('http://foo.com/hello?a[b]=1').body
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_parses_params_with_nested_encoder
|
82
|
-
@stubs.get '/hello' do |env|
|
83
|
-
assert_equal '1', env[:params]['a']['b']
|
84
|
-
[200, {}, 'a']
|
85
|
-
end
|
86
|
-
|
87
|
-
@conn.options.params_encoder = Faraday::NestedParamsEncoder
|
88
|
-
assert_equal 'a', @conn.get('http://foo.com/hello?a[b]=1').body
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_parses_params_with_flat_encoder
|
92
|
-
@stubs.get '/hello' do |env|
|
93
|
-
assert_equal '1', env[:params]['a[b]']
|
94
|
-
[200, {}, 'a']
|
95
|
-
end
|
96
|
-
|
97
|
-
@conn.options.params_encoder = Faraday::FlatParamsEncoder
|
98
|
-
assert_equal 'a', @conn.get('http://foo.com/hello?a[b]=1').body
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_raises_an_error_if_no_stub_is_found_for_request
|
102
|
-
assert_raises Stubs::NotFound do
|
103
|
-
@conn.get('/invalid'){ [200, {}, []] }
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_raises_an_error_if_no_stub_is_found_for_request_without_this_header
|
108
|
-
@stubs.get('/yo', { 'X-HELLO' => 'hello' }) { [200, {}, 'a'] }
|
109
|
-
assert_raises Faraday::Adapter::Test::Stubs::NotFound do
|
110
|
-
@conn.get('/yo')
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.expand_path('../integration', __FILE__)
|
2
|
-
|
3
|
-
module Adapters
|
4
|
-
class TyphoeusTest < Faraday::TestCase
|
5
|
-
|
6
|
-
def adapter() :typhoeus end
|
7
|
-
|
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
|
-
# inconsistent outcomes ranging from successful response to connection error
|
17
|
-
undef :test_proxy_auth_fail if ssl_mode?
|
18
|
-
|
19
|
-
def test_binds_local_socket
|
20
|
-
host = '1.2.3.4'
|
21
|
-
conn = create_connection :request => { :bind => { :host => host } }
|
22
|
-
assert_equal host, conn.options[:bind][:host]
|
23
|
-
end
|
24
|
-
|
25
|
-
end unless jruby?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require File.expand_path('../helper', __FILE__)
|
2
|
-
|
3
|
-
class AuthenticationMiddlewareTest < Faraday::TestCase
|
4
|
-
def conn
|
5
|
-
Faraday::Connection.new('http://example.net/') do |builder|
|
6
|
-
yield(builder)
|
7
|
-
builder.adapter :test do |stub|
|
8
|
-
stub.get('/auth-echo') do |env|
|
9
|
-
[200, {}, env[:request_headers]['Authorization']]
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_basic_middleware_adds_basic_header
|
16
|
-
response = conn { |b| b.request :basic_auth, 'aladdin', 'opensesame' }.get('/auth-echo')
|
17
|
-
assert_equal 'Basic YWxhZGRpbjpvcGVuc2VzYW1l', response.body
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_basic_middleware_adds_basic_header_correctly_with_long_values
|
21
|
-
response = conn { |b| b.request :basic_auth, 'A' * 255, '' }.get('/auth-echo')
|
22
|
-
assert_equal "Basic #{'QUFB' * 85}Og==", response.body
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_basic_middleware_does_not_interfere_with_existing_authorization
|
26
|
-
response = conn { |b| b.request :basic_auth, 'aladdin', 'opensesame' }.
|
27
|
-
get('/auth-echo', nil, :authorization => 'Token token="bar"')
|
28
|
-
assert_equal 'Token token="bar"', response.body
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_token_middleware_adds_token_header
|
32
|
-
response = conn { |b| b.request :token_auth, 'quux' }.get('/auth-echo')
|
33
|
-
assert_equal 'Token token="quux"', response.body
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_token_middleware_includes_other_values_if_provided
|
37
|
-
response = conn { |b|
|
38
|
-
b.request :token_auth, 'baz', :foo => 42
|
39
|
-
}.get('/auth-echo')
|
40
|
-
assert_match(/^Token /, response.body)
|
41
|
-
assert_match(/token="baz"/, response.body)
|
42
|
-
assert_match(/foo="42"/, response.body)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_token_middleware_does_not_interfere_with_existing_authorization
|
46
|
-
response = conn { |b| b.request :token_auth, 'quux' }.
|
47
|
-
get('/auth-echo', nil, :authorization => 'Token token="bar"')
|
48
|
-
assert_equal 'Token token="bar"', response.body
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_authorization_middleware_with_string
|
52
|
-
response = conn { |b|
|
53
|
-
b.request :authorization, 'custom', 'abc def'
|
54
|
-
}.get('/auth-echo')
|
55
|
-
assert_match(/^custom abc def$/, response.body)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_authorization_middleware_with_hash
|
59
|
-
response = conn { |b|
|
60
|
-
b.request :authorization, 'baz', :foo => 42
|
61
|
-
}.get('/auth-echo')
|
62
|
-
assert_match(/^baz /, response.body)
|
63
|
-
assert_match(/foo="42"/, response.body)
|
64
|
-
end
|
65
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
-
require 'stringio'
|
3
|
-
|
4
|
-
class CompositeReadIOTest < Faraday::TestCase
|
5
|
-
Part = Struct.new(:to_io) do
|
6
|
-
def length() to_io.string.length end
|
7
|
-
end
|
8
|
-
|
9
|
-
def part(str)
|
10
|
-
Part.new StringIO.new(str)
|
11
|
-
end
|
12
|
-
|
13
|
-
def composite_io(*parts)
|
14
|
-
Faraday::CompositeReadIO.new(*parts)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_empty
|
18
|
-
io = composite_io
|
19
|
-
assert_equal 0, io.length
|
20
|
-
assert_equal "", io.read
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_empty_returns_nil_for_limited_read
|
24
|
-
assert_nil composite_io.read(1)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_empty_parts_returns_nil_for_limited_read
|
28
|
-
io = composite_io(part(""), part(""))
|
29
|
-
assert_nil io.read(1)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_multipart_read_all
|
33
|
-
io = composite_io(part("abcd"), part("1234"))
|
34
|
-
assert_equal 8, io.length
|
35
|
-
assert_equal "abcd1234", io.read
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_multipart_read_limited
|
39
|
-
io = composite_io(part("abcd"), part("1234"))
|
40
|
-
assert_equal "abc", io.read(3)
|
41
|
-
assert_equal "d12", io.read(3)
|
42
|
-
assert_equal "34", io.read(3)
|
43
|
-
assert_equal nil, io.read(3)
|
44
|
-
assert_equal nil, io.read(3)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_multipart_read_limited_size_larger_than_part
|
48
|
-
io = composite_io(part("abcd"), part("1234"))
|
49
|
-
assert_equal "abcd12", io.read(6)
|
50
|
-
assert_equal "34", io.read(6)
|
51
|
-
assert_equal nil, io.read(6)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_multipart_read_with_blank_parts
|
55
|
-
io = composite_io(part(""), part("abcd"), part(""), part("1234"), part(""))
|
56
|
-
assert_equal "abcd12", io.read(6)
|
57
|
-
assert_equal "34", io.read(6)
|
58
|
-
assert_equal nil, io.read(6)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_multipart_rewind
|
62
|
-
io = composite_io(part("abcd"), part("1234"))
|
63
|
-
assert_equal "abc", io.read(3)
|
64
|
-
assert_equal "d12", io.read(3)
|
65
|
-
io.rewind
|
66
|
-
assert_equal "abc", io.read(3)
|
67
|
-
assert_equal "d1234", io.read(5)
|
68
|
-
assert_equal nil, io.read(3)
|
69
|
-
io.rewind
|
70
|
-
assert_equal "ab", io.read(2)
|
71
|
-
end
|
72
|
-
|
73
|
-
# JRuby enforces types to copy_stream to be String or IO
|
74
|
-
if IO.respond_to?(:copy_stream) && !jruby?
|
75
|
-
def test_compatible_with_copy_stream
|
76
|
-
target_io = StringIO.new
|
77
|
-
def target_io.ensure_open_and_writable
|
78
|
-
# Rubinius compatibility
|
79
|
-
end
|
80
|
-
io = composite_io(part("abcd"), part("1234"))
|
81
|
-
|
82
|
-
Faraday::Timer.timeout(1) do
|
83
|
-
IO.copy_stream(io, target_io)
|
84
|
-
end
|
85
|
-
assert_equal "abcd1234", target_io.string
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
unless RUBY_VERSION < '1.9'
|
90
|
-
def test_read_from_multibyte
|
91
|
-
File.open(File.dirname(__FILE__) + '/multibyte.txt') do |utf8|
|
92
|
-
io = composite_io(part("\x86"), Part.new(utf8))
|
93
|
-
assert_equal bin("\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n"), io.read
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_limited_from_multibyte
|
98
|
-
File.open(File.dirname(__FILE__) + '/multibyte.txt') do |utf8|
|
99
|
-
io = composite_io(part("\x86"), Part.new(utf8))
|
100
|
-
assert_equal bin("\x86\xE3\x83"), io.read(3)
|
101
|
-
assert_equal bin("\x95\xE3\x82"), io.read(3)
|
102
|
-
assert_equal bin("\xA1\xE3\x82\xA4\xE3\x83\xAB\n"), io.read(8)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def bin(str)
|
108
|
-
str.force_encoding("BINARY") if str.respond_to?(:force_encoding)
|
109
|
-
str
|
110
|
-
end
|
111
|
-
end
|