faraday 1.10.3 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +197 -3
  3. data/LICENSE.md +1 -1
  4. data/README.md +34 -20
  5. data/Rakefile +6 -1
  6. data/examples/client_spec.rb +41 -19
  7. data/examples/client_test.rb +48 -22
  8. data/lib/faraday/adapter/test.rb +62 -13
  9. data/lib/faraday/adapter.rb +6 -10
  10. data/lib/faraday/connection.rb +61 -147
  11. data/lib/faraday/encoders/nested_params_encoder.rb +14 -7
  12. data/lib/faraday/error.rb +24 -5
  13. data/lib/faraday/logging/formatter.rb +28 -15
  14. data/lib/faraday/middleware.rb +46 -2
  15. data/lib/faraday/middleware_registry.rb +17 -63
  16. data/lib/faraday/options/connection_options.rb +7 -6
  17. data/lib/faraday/options/env.rb +85 -62
  18. data/lib/faraday/options/proxy_options.rb +7 -3
  19. data/lib/faraday/options/request_options.rb +7 -6
  20. data/lib/faraday/options/ssl_options.rb +56 -45
  21. data/lib/faraday/options.rb +7 -6
  22. data/lib/faraday/rack_builder.rb +23 -21
  23. data/lib/faraday/request/authorization.rb +33 -41
  24. data/lib/faraday/request/instrumentation.rb +5 -1
  25. data/lib/faraday/request/json.rb +18 -3
  26. data/lib/faraday/request/url_encoded.rb +5 -1
  27. data/lib/faraday/request.rb +15 -30
  28. data/lib/faraday/response/json.rb +25 -5
  29. data/lib/faraday/response/logger.rb +6 -0
  30. data/lib/faraday/response/raise_error.rb +35 -6
  31. data/lib/faraday/response.rb +9 -21
  32. data/lib/faraday/utils/headers.rb +15 -4
  33. data/lib/faraday/utils.rb +11 -7
  34. data/lib/faraday/version.rb +1 -1
  35. data/lib/faraday.rb +8 -44
  36. data/spec/faraday/adapter/test_spec.rb +65 -0
  37. data/spec/faraday/connection_spec.rb +165 -93
  38. data/spec/faraday/error_spec.rb +31 -6
  39. data/spec/faraday/middleware_registry_spec.rb +31 -0
  40. data/spec/faraday/middleware_spec.rb +161 -0
  41. data/spec/faraday/options/env_spec.rb +8 -2
  42. data/spec/faraday/options/options_spec.rb +1 -1
  43. data/spec/faraday/options/proxy_options_spec.rb +8 -0
  44. data/spec/faraday/params_encoders/nested_spec.rb +10 -1
  45. data/spec/faraday/rack_builder_spec.rb +26 -54
  46. data/spec/faraday/request/authorization_spec.rb +50 -28
  47. data/spec/faraday/request/instrumentation_spec.rb +5 -7
  48. data/spec/faraday/request/json_spec.rb +88 -0
  49. data/spec/faraday/request/url_encoded_spec.rb +12 -2
  50. data/spec/faraday/request_spec.rb +5 -15
  51. data/spec/faraday/response/json_spec.rb +93 -6
  52. data/spec/faraday/response/logger_spec.rb +38 -0
  53. data/spec/faraday/response/raise_error_spec.rb +91 -5
  54. data/spec/faraday/response_spec.rb +3 -1
  55. data/spec/faraday/utils/headers_spec.rb +31 -4
  56. data/spec/faraday/utils_spec.rb +63 -1
  57. data/spec/faraday_spec.rb +10 -4
  58. data/spec/spec_helper.rb +5 -6
  59. data/spec/support/fake_safe_buffer.rb +1 -1
  60. data/spec/support/faraday_middleware_subclasses.rb +18 -0
  61. data/spec/support/helper_methods.rb +0 -37
  62. data/spec/support/shared_examples/adapter.rb +2 -2
  63. data/spec/support/shared_examples/request_method.rb +22 -21
  64. metadata +18 -154
  65. data/lib/faraday/adapter/typhoeus.rb +0 -15
  66. data/lib/faraday/autoload.rb +0 -87
  67. data/lib/faraday/dependency_loader.rb +0 -39
  68. data/lib/faraday/deprecate.rb +0 -110
  69. data/lib/faraday/request/basic_authentication.rb +0 -20
  70. data/lib/faraday/request/token_authentication.rb +0 -20
  71. data/spec/faraday/adapter/em_http_spec.rb +0 -49
  72. data/spec/faraday/adapter/em_synchrony_spec.rb +0 -18
  73. data/spec/faraday/adapter/excon_spec.rb +0 -49
  74. data/spec/faraday/adapter/httpclient_spec.rb +0 -73
  75. data/spec/faraday/adapter/net_http_spec.rb +0 -64
  76. data/spec/faraday/adapter/patron_spec.rb +0 -18
  77. data/spec/faraday/adapter/rack_spec.rb +0 -8
  78. data/spec/faraday/adapter/typhoeus_spec.rb +0 -7
  79. data/spec/faraday/composite_read_io_spec.rb +0 -80
  80. data/spec/faraday/deprecate_spec.rb +0 -147
  81. data/spec/faraday/response/middleware_spec.rb +0 -68
  82. 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