faraday 0.17.3 → 2.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +350 -8
- data/LICENSE.md +1 -1
- data/README.md +27 -367
- data/Rakefile +1 -7
- data/examples/client_spec.rb +119 -0
- data/examples/client_test.rb +144 -0
- data/lib/faraday/adapter/test.rb +170 -72
- data/lib/faraday/adapter.rb +69 -23
- data/lib/faraday/adapter_registry.rb +30 -0
- data/lib/faraday/connection.rb +309 -233
- data/lib/faraday/encoders/flat_params_encoder.rb +105 -0
- data/lib/faraday/encoders/nested_params_encoder.rb +183 -0
- data/lib/faraday/error.rb +31 -42
- data/lib/faraday/logging/formatter.rb +122 -0
- data/lib/faraday/methods.rb +6 -0
- data/lib/faraday/middleware.rb +21 -25
- data/lib/faraday/middleware_registry.rb +83 -0
- data/lib/faraday/options/connection_options.rb +22 -0
- data/lib/faraday/options/env.rb +205 -0
- data/lib/faraday/options/proxy_options.rb +32 -0
- data/lib/faraday/options/request_options.rb +22 -0
- data/lib/faraday/options/ssl_options.rb +69 -0
- data/lib/faraday/options.rb +38 -193
- data/lib/faraday/parameters.rb +4 -197
- data/lib/faraday/rack_builder.rb +91 -76
- data/lib/faraday/request/authorization.rb +42 -29
- data/lib/faraday/request/instrumentation.rb +47 -27
- data/lib/faraday/request/json.rb +55 -0
- data/lib/faraday/request/url_encoded.rb +48 -24
- data/lib/faraday/request.rb +64 -42
- data/lib/faraday/response/json.rb +54 -0
- data/lib/faraday/response/logger.rb +24 -67
- data/lib/faraday/response/raise_error.rb +57 -18
- data/lib/faraday/response.rb +26 -32
- data/lib/faraday/utils/headers.rb +144 -0
- data/lib/faraday/utils/params_hash.rb +61 -0
- data/lib/faraday/utils.rb +47 -251
- data/lib/faraday/version.rb +5 -0
- data/lib/faraday.rb +108 -198
- data/spec/external_adapters/faraday_specs_setup.rb +14 -0
- data/spec/faraday/adapter/test_spec.rb +442 -0
- data/spec/faraday/adapter_registry_spec.rb +28 -0
- data/spec/faraday/adapter_spec.rb +55 -0
- data/spec/faraday/connection_spec.rb +808 -0
- data/spec/faraday/error_spec.rb +12 -54
- data/spec/faraday/middleware_registry_spec.rb +31 -0
- data/spec/faraday/middleware_spec.rb +70 -0
- data/spec/faraday/options/env_spec.rb +76 -0
- data/spec/faraday/options/options_spec.rb +297 -0
- data/spec/faraday/options/proxy_options_spec.rb +44 -0
- data/spec/faraday/options/request_options_spec.rb +19 -0
- data/spec/faraday/params_encoders/flat_spec.rb +42 -0
- data/spec/faraday/params_encoders/nested_spec.rb +150 -0
- data/spec/faraday/rack_builder_spec.rb +317 -0
- data/spec/faraday/request/authorization_spec.rb +118 -0
- data/spec/faraday/request/instrumentation_spec.rb +74 -0
- data/spec/faraday/request/json_spec.rb +111 -0
- data/spec/faraday/request/url_encoded_spec.rb +93 -0
- data/spec/faraday/request_spec.rb +110 -0
- data/spec/faraday/response/json_spec.rb +117 -0
- data/spec/faraday/response/logger_spec.rb +248 -0
- data/spec/faraday/response/raise_error_spec.rb +81 -15
- data/spec/faraday/response_spec.rb +77 -0
- data/spec/faraday/utils/headers_spec.rb +100 -0
- data/spec/faraday/utils_spec.rb +118 -0
- data/spec/faraday_spec.rb +37 -0
- data/spec/spec_helper.rb +63 -36
- data/spec/support/disabling_stub.rb +14 -0
- data/spec/support/fake_safe_buffer.rb +15 -0
- data/spec/support/helper_methods.rb +96 -0
- data/spec/support/shared_examples/adapter.rb +105 -0
- data/spec/support/shared_examples/params_encoder.rb +18 -0
- data/spec/support/shared_examples/request_method.rb +263 -0
- data/spec/support/streaming_response_checker.rb +35 -0
- metadata +76 -59
- data/lib/faraday/adapter/em_http.rb +0 -243
- data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -56
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -66
- data/lib/faraday/adapter/em_synchrony.rb +0 -106
- data/lib/faraday/adapter/excon.rb +0 -82
- data/lib/faraday/adapter/httpclient.rb +0 -128
- data/lib/faraday/adapter/net_http.rb +0 -152
- data/lib/faraday/adapter/net_http_persistent.rb +0 -68
- data/lib/faraday/adapter/patron.rb +0 -95
- data/lib/faraday/adapter/rack.rb +0 -58
- data/lib/faraday/adapter/typhoeus.rb +0 -12
- data/lib/faraday/autoload.rb +0 -84
- data/lib/faraday/deprecate.rb +0 -107
- data/lib/faraday/request/basic_authentication.rb +0 -13
- data/lib/faraday/request/multipart.rb +0 -68
- data/lib/faraday/request/retry.rb +0 -213
- data/lib/faraday/request/token_authentication.rb +0 -15
- data/lib/faraday/upload_io.rb +0 -67
- data/spec/faraday/deprecate_spec.rb +0 -69
- data/test/adapters/default_test.rb +0 -14
- data/test/adapters/em_http_test.rb +0 -30
- data/test/adapters/em_synchrony_test.rb +0 -32
- data/test/adapters/excon_test.rb +0 -30
- data/test/adapters/httpclient_test.rb +0 -34
- data/test/adapters/integration.rb +0 -263
- data/test/adapters/logger_test.rb +0 -136
- data/test/adapters/net_http_persistent_test.rb +0 -114
- data/test/adapters/net_http_test.rb +0 -79
- data/test/adapters/patron_test.rb +0 -40
- data/test/adapters/rack_test.rb +0 -38
- data/test/adapters/test_middleware_test.rb +0 -157
- data/test/adapters/typhoeus_test.rb +0 -38
- data/test/authentication_middleware_test.rb +0 -65
- data/test/composite_read_io_test.rb +0 -109
- data/test/connection_test.rb +0 -738
- data/test/env_test.rb +0 -268
- data/test/helper.rb +0 -75
- data/test/live_server.rb +0 -67
- data/test/middleware/instrumentation_test.rb +0 -88
- data/test/middleware/retry_test.rb +0 -282
- data/test/middleware_stack_test.rb +0 -260
- data/test/multibyte.txt +0 -1
- data/test/options_test.rb +0 -333
- data/test/parameters_test.rb +0 -157
- data/test/request_middleware_test.rb +0 -126
- data/test/response_middleware_test.rb +0 -72
- data/test/strawberry.rb +0 -2
- data/test/utils_test.rb +0 -98
data/test/utils_test.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require File.expand_path('../helper', __FILE__)
|
2
|
-
|
3
|
-
class TestUtils < Faraday::TestCase
|
4
|
-
|
5
|
-
# Headers parsing
|
6
|
-
|
7
|
-
def test_headers
|
8
|
-
"HTTP/1.x 500 OK\r\nContent-Type: text/html; charset=UTF-8\r\n" \
|
9
|
-
"HTTP/1.x 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n"
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_headers_parsing_for_aggregated_responses
|
13
|
-
headers = Faraday::Utils::Headers.new()
|
14
|
-
headers.parse(test_headers)
|
15
|
-
|
16
|
-
result = headers.to_hash
|
17
|
-
|
18
|
-
assert_equal result["Content-Type"], "application/json; charset=UTF-8"
|
19
|
-
end
|
20
|
-
|
21
|
-
# URI parsing
|
22
|
-
|
23
|
-
def setup
|
24
|
-
@url = "http://example.com/abc"
|
25
|
-
end
|
26
|
-
|
27
|
-
# emulates ActiveSupport::SafeBuffer#gsub
|
28
|
-
FakeSafeBuffer = Struct.new(:string) do
|
29
|
-
def to_s() self end
|
30
|
-
def gsub(regex)
|
31
|
-
string.gsub(regex) {
|
32
|
-
match, = $&, '' =~ /a/
|
33
|
-
yield(match)
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_escaping_safe_buffer
|
39
|
-
str = FakeSafeBuffer.new('$32,000.00')
|
40
|
-
assert_equal '%2432%2C000.00', Faraday::Utils.escape(str)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_parses_with_default
|
44
|
-
with_default_uri_parser(nil) do
|
45
|
-
uri = normalize(@url)
|
46
|
-
assert_equal 'example.com', uri.host
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_parses_with_URI
|
51
|
-
with_default_uri_parser(::URI) do
|
52
|
-
uri = normalize(@url)
|
53
|
-
assert_equal 'example.com', uri.host
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_parses_with_block
|
58
|
-
with_default_uri_parser(lambda {|u| "booya#{"!" * u.size}" }) do
|
59
|
-
assert_equal 'booya!!!!!!!!!!!!!!!!!!!!!!', normalize(@url)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_replace_header_hash
|
64
|
-
headers = Faraday::Utils::Headers.new('authorization' => 't0ps3cr3t!')
|
65
|
-
assert headers.include?('authorization')
|
66
|
-
|
67
|
-
headers.replace({'content-type' => 'text/plain'})
|
68
|
-
|
69
|
-
assert !headers.include?('authorization')
|
70
|
-
end
|
71
|
-
|
72
|
-
def normalize(url)
|
73
|
-
Faraday::Utils::URI(url)
|
74
|
-
end
|
75
|
-
|
76
|
-
def with_default_uri_parser(parser)
|
77
|
-
old_parser = Faraday::Utils.default_uri_parser
|
78
|
-
begin
|
79
|
-
Faraday::Utils.default_uri_parser = parser
|
80
|
-
yield
|
81
|
-
ensure
|
82
|
-
Faraday::Utils.default_uri_parser = old_parser
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# YAML parsing
|
87
|
-
|
88
|
-
def test_headers_yaml_roundtrip
|
89
|
-
headers = Faraday::Utils::Headers.new('User-Agent' => 'safari', 'Content-type' => 'text/html')
|
90
|
-
result = YAML.load(headers.to_yaml)
|
91
|
-
|
92
|
-
assert result.include?('user-agent'), 'Unable to hydrate to a correct Headers'
|
93
|
-
assert result.include?('content-type'), 'Unable to hydrate to a correct Headers'
|
94
|
-
assert result['user-agent'] == 'safari', 'Unable to access rehydrated Headers'
|
95
|
-
assert result['content-type'] == 'text/html', 'Unable to access rehydrated Headers'
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|