faraday 1.4.1 → 2.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +197 -3
  3. data/LICENSE.md +1 -1
  4. data/README.md +18 -16
  5. data/examples/client_spec.rb +67 -13
  6. data/examples/client_test.rb +80 -15
  7. data/lib/faraday/adapter/test.rb +117 -52
  8. data/lib/faraday/adapter.rb +5 -14
  9. data/lib/faraday/connection.rb +64 -119
  10. data/lib/faraday/encoders/nested_params_encoder.rb +13 -6
  11. data/lib/faraday/error.rb +3 -8
  12. data/lib/faraday/logging/formatter.rb +19 -2
  13. data/lib/faraday/middleware.rb +3 -1
  14. data/lib/faraday/middleware_registry.rb +17 -63
  15. data/lib/faraday/options/env.rb +31 -7
  16. data/lib/faraday/options/proxy_options.rb +4 -0
  17. data/lib/faraday/options/ssl_options.rb +11 -1
  18. data/lib/faraday/options.rb +3 -3
  19. data/lib/faraday/rack_builder.rb +23 -20
  20. data/lib/faraday/request/authorization.rb +37 -38
  21. data/lib/faraday/request/instrumentation.rb +2 -0
  22. data/lib/faraday/request/json.rb +55 -0
  23. data/lib/faraday/request/url_encoded.rb +5 -1
  24. data/lib/faraday/request.rb +12 -32
  25. data/lib/faraday/response/json.rb +54 -0
  26. data/lib/faraday/response/logger.rb +8 -4
  27. data/lib/faraday/response/raise_error.rb +9 -1
  28. data/lib/faraday/response.rb +10 -20
  29. data/lib/faraday/utils/headers.rb +7 -2
  30. data/lib/faraday/utils.rb +10 -5
  31. data/lib/faraday/version.rb +1 -1
  32. data/lib/faraday.rb +10 -31
  33. data/spec/faraday/adapter/test_spec.rb +182 -0
  34. data/spec/faraday/connection_spec.rb +177 -90
  35. data/spec/faraday/middleware_registry_spec.rb +31 -0
  36. data/spec/faraday/middleware_spec.rb +18 -0
  37. data/spec/faraday/options/env_spec.rb +8 -2
  38. data/spec/faraday/options/proxy_options_spec.rb +7 -0
  39. data/spec/faraday/params_encoders/nested_spec.rb +8 -0
  40. data/spec/faraday/rack_builder_spec.rb +26 -54
  41. data/spec/faraday/request/authorization_spec.rb +54 -24
  42. data/spec/faraday/request/instrumentation_spec.rb +5 -7
  43. data/spec/faraday/request/json_spec.rb +111 -0
  44. data/spec/faraday/request/url_encoded_spec.rb +12 -2
  45. data/spec/faraday/request_spec.rb +5 -15
  46. data/spec/faraday/response/json_spec.rb +117 -0
  47. data/spec/faraday/response/logger_spec.rb +28 -0
  48. data/spec/faraday/response/raise_error_spec.rb +7 -4
  49. data/spec/faraday/response_spec.rb +3 -1
  50. data/spec/faraday/utils/headers_spec.rb +22 -4
  51. data/spec/faraday/utils_spec.rb +63 -1
  52. data/spec/support/fake_safe_buffer.rb +1 -1
  53. data/spec/support/helper_methods.rb +0 -37
  54. data/spec/support/shared_examples/adapter.rb +2 -2
  55. data/spec/support/shared_examples/request_method.rb +22 -21
  56. metadata +14 -80
  57. data/lib/faraday/adapter/em_http.rb +0 -289
  58. data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -62
  59. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -69
  60. data/lib/faraday/adapter/em_synchrony.rb +0 -153
  61. data/lib/faraday/adapter/httpclient.rb +0 -152
  62. data/lib/faraday/adapter/patron.rb +0 -132
  63. data/lib/faraday/adapter/rack.rb +0 -75
  64. data/lib/faraday/adapter/typhoeus.rb +0 -15
  65. data/lib/faraday/autoload.rb +0 -92
  66. data/lib/faraday/dependency_loader.rb +0 -37
  67. data/lib/faraday/file_part.rb +0 -128
  68. data/lib/faraday/param_part.rb +0 -53
  69. data/lib/faraday/request/basic_authentication.rb +0 -20
  70. data/lib/faraday/request/multipart.rb +0 -106
  71. data/lib/faraday/request/retry.rb +0 -239
  72. data/lib/faraday/request/token_authentication.rb +0 -20
  73. data/spec/faraday/adapter/em_http_spec.rb +0 -47
  74. data/spec/faraday/adapter/em_synchrony_spec.rb +0 -16
  75. data/spec/faraday/adapter/excon_spec.rb +0 -49
  76. data/spec/faraday/adapter/httpclient_spec.rb +0 -73
  77. data/spec/faraday/adapter/net_http_spec.rb +0 -64
  78. data/spec/faraday/adapter/patron_spec.rb +0 -18
  79. data/spec/faraday/adapter/rack_spec.rb +0 -8
  80. data/spec/faraday/adapter/typhoeus_spec.rb +0 -7
  81. data/spec/faraday/composite_read_io_spec.rb +0 -80
  82. data/spec/faraday/request/multipart_spec.rb +0 -302
  83. data/spec/faraday/request/retry_spec.rb +0 -242
  84. data/spec/faraday/response/middleware_spec.rb +0 -68
  85. 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