faraday 1.10.3 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +197 -3
- data/LICENSE.md +1 -1
- data/README.md +34 -20
- data/Rakefile +6 -1
- data/examples/client_spec.rb +41 -19
- data/examples/client_test.rb +48 -22
- data/lib/faraday/adapter/test.rb +62 -13
- data/lib/faraday/adapter.rb +6 -10
- data/lib/faraday/connection.rb +61 -147
- data/lib/faraday/encoders/nested_params_encoder.rb +14 -7
- data/lib/faraday/error.rb +24 -5
- data/lib/faraday/logging/formatter.rb +28 -15
- data/lib/faraday/middleware.rb +46 -2
- data/lib/faraday/middleware_registry.rb +17 -63
- data/lib/faraday/options/connection_options.rb +7 -6
- data/lib/faraday/options/env.rb +85 -62
- data/lib/faraday/options/proxy_options.rb +7 -3
- data/lib/faraday/options/request_options.rb +7 -6
- data/lib/faraday/options/ssl_options.rb +56 -45
- data/lib/faraday/options.rb +7 -6
- data/lib/faraday/rack_builder.rb +23 -21
- data/lib/faraday/request/authorization.rb +33 -41
- data/lib/faraday/request/instrumentation.rb +5 -1
- data/lib/faraday/request/json.rb +18 -3
- data/lib/faraday/request/url_encoded.rb +5 -1
- data/lib/faraday/request.rb +15 -30
- data/lib/faraday/response/json.rb +25 -5
- data/lib/faraday/response/logger.rb +6 -0
- data/lib/faraday/response/raise_error.rb +35 -6
- data/lib/faraday/response.rb +9 -21
- data/lib/faraday/utils/headers.rb +15 -4
- data/lib/faraday/utils.rb +11 -7
- data/lib/faraday/version.rb +1 -1
- data/lib/faraday.rb +8 -44
- data/spec/faraday/adapter/test_spec.rb +65 -0
- data/spec/faraday/connection_spec.rb +165 -93
- data/spec/faraday/error_spec.rb +31 -6
- data/spec/faraday/middleware_registry_spec.rb +31 -0
- data/spec/faraday/middleware_spec.rb +161 -0
- data/spec/faraday/options/env_spec.rb +8 -2
- data/spec/faraday/options/options_spec.rb +1 -1
- data/spec/faraday/options/proxy_options_spec.rb +8 -0
- data/spec/faraday/params_encoders/nested_spec.rb +10 -1
- data/spec/faraday/rack_builder_spec.rb +26 -54
- data/spec/faraday/request/authorization_spec.rb +50 -28
- data/spec/faraday/request/instrumentation_spec.rb +5 -7
- data/spec/faraday/request/json_spec.rb +88 -0
- data/spec/faraday/request/url_encoded_spec.rb +12 -2
- data/spec/faraday/request_spec.rb +5 -15
- data/spec/faraday/response/json_spec.rb +93 -6
- data/spec/faraday/response/logger_spec.rb +38 -0
- data/spec/faraday/response/raise_error_spec.rb +91 -5
- data/spec/faraday/response_spec.rb +3 -1
- data/spec/faraday/utils/headers_spec.rb +31 -4
- data/spec/faraday/utils_spec.rb +63 -1
- data/spec/faraday_spec.rb +10 -4
- data/spec/spec_helper.rb +5 -6
- data/spec/support/fake_safe_buffer.rb +1 -1
- data/spec/support/faraday_middleware_subclasses.rb +18 -0
- data/spec/support/helper_methods.rb +0 -37
- data/spec/support/shared_examples/adapter.rb +2 -2
- data/spec/support/shared_examples/request_method.rb +22 -21
- metadata +18 -154
- data/lib/faraday/adapter/typhoeus.rb +0 -15
- data/lib/faraday/autoload.rb +0 -87
- data/lib/faraday/dependency_loader.rb +0 -39
- data/lib/faraday/deprecate.rb +0 -110
- data/lib/faraday/request/basic_authentication.rb +0 -20
- data/lib/faraday/request/token_authentication.rb +0 -20
- data/spec/faraday/adapter/em_http_spec.rb +0 -49
- data/spec/faraday/adapter/em_synchrony_spec.rb +0 -18
- data/spec/faraday/adapter/excon_spec.rb +0 -49
- data/spec/faraday/adapter/httpclient_spec.rb +0 -73
- data/spec/faraday/adapter/net_http_spec.rb +0 -64
- data/spec/faraday/adapter/patron_spec.rb +0 -18
- data/spec/faraday/adapter/rack_spec.rb +0 -8
- data/spec/faraday/adapter/typhoeus_spec.rb +0 -7
- data/spec/faraday/composite_read_io_spec.rb +0 -80
- data/spec/faraday/deprecate_spec.rb +0 -147
- data/spec/faraday/response/middleware_spec.rb +0 -68
- data/spec/support/webmock_rack_app.rb +0 -68
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Rack app used to test the Rack adapter.
|
4
|
-
# Uses Webmock to check if requests are registered, in which case it returns
|
5
|
-
# the registered response.
|
6
|
-
class WebmockRackApp
|
7
|
-
def call(env)
|
8
|
-
req_signature = WebMock::RequestSignature.new(
|
9
|
-
req_method(env),
|
10
|
-
req_uri(env),
|
11
|
-
body: req_body(env),
|
12
|
-
headers: req_headers(env)
|
13
|
-
)
|
14
|
-
|
15
|
-
WebMock::RequestRegistry
|
16
|
-
.instance
|
17
|
-
.requested_signatures
|
18
|
-
.put(req_signature)
|
19
|
-
|
20
|
-
process_response(req_signature)
|
21
|
-
end
|
22
|
-
|
23
|
-
def req_method(env)
|
24
|
-
env['REQUEST_METHOD'].downcase.to_sym
|
25
|
-
end
|
26
|
-
|
27
|
-
def req_uri(env)
|
28
|
-
scheme = env['rack.url_scheme']
|
29
|
-
host = env['SERVER_NAME']
|
30
|
-
port = env['SERVER_PORT']
|
31
|
-
path = env['PATH_INFO']
|
32
|
-
query = env['QUERY_STRING']
|
33
|
-
|
34
|
-
url = +"#{scheme}://#{host}:#{port}#{path}"
|
35
|
-
url += "?#{query}" if query
|
36
|
-
|
37
|
-
uri = WebMock::Util::URI.heuristic_parse(url)
|
38
|
-
uri.path = uri.normalized_path.gsub('[^:]//', '/')
|
39
|
-
uri
|
40
|
-
end
|
41
|
-
|
42
|
-
def req_headers(env)
|
43
|
-
http_headers = env.select { |k, _| k.start_with?('HTTP_') }
|
44
|
-
.map { |k, v| [k[5..-1], v] }
|
45
|
-
.to_h
|
46
|
-
|
47
|
-
special_headers = Faraday::Adapter::Rack::SPECIAL_HEADERS
|
48
|
-
http_headers.merge(env.select { |k, _| special_headers.include?(k) })
|
49
|
-
end
|
50
|
-
|
51
|
-
def req_body(env)
|
52
|
-
env['rack.input'].read
|
53
|
-
end
|
54
|
-
|
55
|
-
def process_response(req_signature)
|
56
|
-
res = WebMock::StubRegistry.instance.response_for_request(req_signature)
|
57
|
-
|
58
|
-
if res.nil? && req_signature.uri.host == 'localhost'
|
59
|
-
raise Faraday::ConnectionFailed, 'Trying to connect to localhost'
|
60
|
-
end
|
61
|
-
|
62
|
-
raise WebMock::NetConnectNotAllowedError, req_signature unless res
|
63
|
-
|
64
|
-
raise Faraday::TimeoutError if res.should_timeout
|
65
|
-
|
66
|
-
[res.status[0], res.headers || {}, [res.body || '']]
|
67
|
-
end
|
68
|
-
end
|