faraday 1.4.1 → 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 +197 -3
- data/LICENSE.md +1 -1
- data/README.md +18 -16
- data/examples/client_spec.rb +67 -13
- data/examples/client_test.rb +80 -15
- data/lib/faraday/adapter/test.rb +117 -52
- data/lib/faraday/adapter.rb +5 -14
- data/lib/faraday/connection.rb +64 -119
- data/lib/faraday/encoders/nested_params_encoder.rb +13 -6
- data/lib/faraday/error.rb +3 -8
- data/lib/faraday/logging/formatter.rb +19 -2
- data/lib/faraday/middleware.rb +3 -1
- data/lib/faraday/middleware_registry.rb +17 -63
- data/lib/faraday/options/env.rb +31 -7
- data/lib/faraday/options/proxy_options.rb +4 -0
- data/lib/faraday/options/ssl_options.rb +11 -1
- data/lib/faraday/options.rb +3 -3
- data/lib/faraday/rack_builder.rb +23 -20
- data/lib/faraday/request/authorization.rb +37 -38
- data/lib/faraday/request/instrumentation.rb +2 -0
- data/lib/faraday/request/json.rb +55 -0
- data/lib/faraday/request/url_encoded.rb +5 -1
- data/lib/faraday/request.rb +12 -32
- data/lib/faraday/response/json.rb +54 -0
- data/lib/faraday/response/logger.rb +8 -4
- data/lib/faraday/response/raise_error.rb +9 -1
- data/lib/faraday/response.rb +10 -20
- data/lib/faraday/utils/headers.rb +7 -2
- data/lib/faraday/utils.rb +10 -5
- data/lib/faraday/version.rb +1 -1
- data/lib/faraday.rb +10 -31
- data/spec/faraday/adapter/test_spec.rb +182 -0
- data/spec/faraday/connection_spec.rb +177 -90
- data/spec/faraday/middleware_registry_spec.rb +31 -0
- data/spec/faraday/middleware_spec.rb +18 -0
- data/spec/faraday/options/env_spec.rb +8 -2
- data/spec/faraday/options/proxy_options_spec.rb +7 -0
- data/spec/faraday/params_encoders/nested_spec.rb +8 -0
- data/spec/faraday/rack_builder_spec.rb +26 -54
- data/spec/faraday/request/authorization_spec.rb +54 -24
- data/spec/faraday/request/instrumentation_spec.rb +5 -7
- data/spec/faraday/request/json_spec.rb +111 -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 +117 -0
- data/spec/faraday/response/logger_spec.rb +28 -0
- data/spec/faraday/response/raise_error_spec.rb +7 -4
- data/spec/faraday/response_spec.rb +3 -1
- data/spec/faraday/utils/headers_spec.rb +22 -4
- data/spec/faraday/utils_spec.rb +63 -1
- data/spec/support/fake_safe_buffer.rb +1 -1
- 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 +14 -80
- data/lib/faraday/adapter/em_http.rb +0 -289
- data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -62
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -69
- data/lib/faraday/adapter/em_synchrony.rb +0 -153
- data/lib/faraday/adapter/httpclient.rb +0 -152
- data/lib/faraday/adapter/patron.rb +0 -132
- data/lib/faraday/adapter/rack.rb +0 -75
- data/lib/faraday/adapter/typhoeus.rb +0 -15
- data/lib/faraday/autoload.rb +0 -92
- data/lib/faraday/dependency_loader.rb +0 -37
- data/lib/faraday/file_part.rb +0 -128
- data/lib/faraday/param_part.rb +0 -53
- data/lib/faraday/request/basic_authentication.rb +0 -20
- data/lib/faraday/request/multipart.rb +0 -106
- data/lib/faraday/request/retry.rb +0 -239
- data/lib/faraday/request/token_authentication.rb +0 -20
- data/spec/faraday/adapter/em_http_spec.rb +0 -47
- data/spec/faraday/adapter/em_synchrony_spec.rb +0 -16
- 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/request/multipart_spec.rb +0 -302
- data/spec/faraday/request/retry_spec.rb +0 -242
- 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
|