faraday 1.1.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47236f354f9fda55254c8bd2b9e3552de12e8894fcecea0035ffbeb3ccc46b9c
4
- data.tar.gz: f6eb36d3da02314fe799368c1ff4c17c5841f0badd18c5a89772e00bae43065c
3
+ metadata.gz: 84198a1e84bf10f350bad8dea5ebd4a866a9dff523d7b84ccad92ef9cb32b366
4
+ data.tar.gz: b4d0537c7d4b5a8fba689bd84167246560cf8e2fd9ba492ab6e00b7d1e6f4f40
5
5
  SHA512:
6
- metadata.gz: 300153861873b2a5b3a3a9f552c47a2b70dd083ffd5478d8eca2c4c2005e5a74d09d962b51fb9a780ea90bb1ac87bdfa902639e86b2147d5b4d4374791789bd1
7
- data.tar.gz: 3628d85508cdd669111ae6175b6b5a191380d0d405f345612f6342e487aec0f3cc9d2e1726a2cdde7d82ee86fae82aa41f4a62ea330343598383ae3f644b5a85
6
+ metadata.gz: a6e2b78cfe4ed8c203d87426cf4e2c1a1f1811550f1deeef3fdad7b691ea29a7a23f62b3460b5e701585b1375c4321e573e7f2ac2fd6834eba0b63772a36c858
7
+ data.tar.gz: 75e1d9a707a37fd042d599959e62d2b4b679aa66e9194e2199295d6a190acd0a9dc366690c45a60cfb4aa6aa67b6bea7757fd40cb58d2560fe87f8de67271430
data/CHANGELOG.md CHANGED
@@ -1,5 +1,109 @@
1
1
  # Faraday Changelog
2
2
 
3
+ ## [v1.3.0](https://github.com/lostisland/faraday/releases/tag/v1.3.0) (2020-12-31)
4
+
5
+ ### Highlights
6
+ Faraday v1.3.0 is the first release to officially support Ruby 3.0 in the CI pipeline 🎉 🍾!
7
+
8
+ This is also the first release with a previously "included" adapter (Net::HTTP) being isolated into a [separate gem](https://github.com/lostisland/faraday-net_http) 🎊!
9
+ The new adapter is added to Faraday as a dependency for now, so that means full backwards-compatibility, but just to be safe be careful when upgrading!
10
+
11
+ This is a huge step towards are Faraday v2.0 objective of pushing adapters and middleware into separate gems.
12
+ Many thanks to the Faraday Team, @JanDintel and everyone who attended the [ROSS Conf remote event](https://www.rossconf.io/event/remote/)
13
+
14
+ ### Features
15
+
16
+ * Improves consistency with Faraday::Error and Faraday::RaiseError (#1229, @qsona, @iMacTia)
17
+
18
+ ### Fixes
19
+
20
+ * Don't assign to global ::Timer (#1227, @bpo)
21
+
22
+ ### Documentation
23
+
24
+ * CHANGELOG: add releases after 1.0 (#1225, @olleolleolle)
25
+ * Improves retry middleware documentation. (#1228, @iMacTia)
26
+
27
+ ### Misc
28
+
29
+ * Move out Net::HTTP adapter (#1222, @JanDintel, @iMacTia)
30
+ * Adds Ruby 3.0 to CI Matrix (#1226, @iMacTia)
31
+
32
+
33
+ ## [v1.2.0](https://github.com/lostisland/faraday/releases/tag/v1.2.0) (2020-12-23)
34
+
35
+ ### Features
36
+
37
+ * Introduces `on_request` and `on_complete` methods in `Faraday::Middleware`. (#1194, @iMacTia)
38
+
39
+ ### Fixes
40
+
41
+ * Require 'date' to avoid retry exception (#1206, @rustygeldmacher)
42
+ * Fix rdebug recursion issue (#1205, @native-api)
43
+ * Update call to `em_http_ssl_patch` (#1202, @kylekeesling)
44
+ * `EmHttp` adapter: drop superfluous loaded? check (#1213, @olleolleolle)
45
+ * Avoid 1 use of keyword hackery (#1211, @grosser)
46
+ * Fix #1219 `Net::HTTP` still uses env proxy (#1221, @iMacTia)
47
+
48
+ ### Documentation
49
+
50
+ * Add comment in gemspec to explain exposure of `examples` and `spec` folders. (#1192, @iMacTia)
51
+ * Adapters, how to create them (#1193, @olleolleolle)
52
+ * Update documentation on using the logger (#1196, @tijmenb)
53
+ * Adjust the retry documentation and spec to align with implementation (#1198, @nbeyer)
54
+
55
+ ### Misc
56
+
57
+ * Test against ruby head (#1208, @grosser)
58
+
59
+ ## [v1.1.0](https://github.com/lostisland/faraday/releases/tag/v1.1.0) (2020-10-17)
60
+
61
+ ### Features
62
+
63
+ * Makes parameters sorting configurable (#1162 @wishdev)
64
+ * Introduces `flat_encode` option for multipart adapter. (#1163 @iMacTia)
65
+ * Include request info in exceptions raised by RaiseError Middleware (#1181 @SandroDamilano)
66
+
67
+ ### Fixes
68
+
69
+ * Avoid `last arg as keyword param` warning when building user middleware on Ruby 2.7 (#1153 @dgholz)
70
+ * Limits net-http-persistent version to < 4.0 (#1156 @iMacTia)
71
+ * Update `typhoeus` to new stable version (`1.4`) (#1159 @AlexWayfer)
72
+ * Properly fix test failure with Rack 2.1+. (#1171 @voxik)
73
+
74
+ ### Documentation
75
+
76
+ * Improves documentation on how to contribute to the site by using Docker. (#1175 @iMacTia)
77
+ * Remove retry_change_requests from documentation (#1185 @stim371)
78
+
79
+ ### Misc
80
+
81
+ * Link from GitHub Actions badge to CI workflow (#1141 @olleolleolle)
82
+ * Return tests of `Test` adapter (#1147 @AlexWayfer)
83
+ * Add 1.0 release to wording in CONTRIBUTING (#1155 @olleolleolle)
84
+ * Fix linting bumping Rubocop to 0.90.0 (#1182 @iMacTia)
85
+ * Drop `git ls-files` in gemspec (#1183 @utkarsh2102)
86
+ * Upgrade CI to ruby/setup-ruby (#1187 @gogainda)
87
+
88
+ ## [v1.0.1](https://github.com/lostisland/faraday/releases/tag/v1.0.1) (2020-03-29)
89
+
90
+ ### Fixes
91
+
92
+ * Use Net::HTTP#start(&block) to ensure closed TCP connections (#1117)
93
+ * Fully qualify constants to be checked (#1122)
94
+ * Allows `parse` method to be private/protected in response middleware (#1123)
95
+ * Encode Spaces in Query Strings as '%20' Instead of '+' (#1125)
96
+ * Limits rack to v2.0.x (#1127)
97
+ * Adapter Registry reads also use mutex (#1136)
98
+
99
+ ### Documentation
100
+
101
+ * Retry middleware documentation fix (#1109)
102
+ * Docs(retry): precise usage of retry-after (#1111)
103
+ * README: Link the logo to the website (#1112)
104
+ * Website: add search bar (#1116)
105
+ * Fix request/response mix-up in docs text (#1132)
106
+
3
107
  ## v1.0
4
108
 
5
109
  Features:
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/faraday.svg)](https://rubygems.org/gems/faraday)
4
4
  [![GitHub Actions CI](https://github.com/lostisland/faraday/workflows/CI/badge.svg)](https://github.com/lostisland/faraday/actions?query=workflow%3ACI)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/f869daab091ceef1da73/maintainability)](https://codeclimate.com/github/lostisland/faraday/maintainability)
6
5
  [![Gitter](https://badges.gitter.im/lostisland/faraday.svg)](https://gitter.im/lostisland/faraday?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
7
6
 
8
7
 
@@ -47,7 +46,7 @@ But before you start coding, please read our [Contributing Guide][contributing]
47
46
  [website]: https://lostisland.github.io/faraday
48
47
  [faraday_team]: https://lostisland.github.io/faraday/team
49
48
  [contributing]: https://github.com/lostisland/faraday/blob/master/.github/CONTRIBUTING.md
50
- [apidoc]: http://www.rubydoc.info/gems/faraday
49
+ [apidoc]: https://www.rubydoc.info/github/lostisland/faraday
51
50
  [actions]: https://github.com/lostisland/faraday/actions
52
51
  [jruby]: http://jruby.org/
53
52
  [rubinius]: http://rubini.us/
data/lib/faraday.rb CHANGED
@@ -1,11 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'cgi'
4
+ require 'date'
4
5
  require 'set'
5
6
  require 'forwardable'
6
7
  require 'faraday/middleware_registry'
7
8
  require 'faraday/dependency_loader'
8
9
 
10
+ unless defined?(::Faraday::Timer)
11
+ require 'timeout'
12
+ ::Faraday::Timer = Timeout
13
+ end
14
+
15
+ require 'faraday/version'
16
+ require 'faraday/methods'
17
+ require 'faraday/utils'
18
+ require 'faraday/options'
19
+ require 'faraday/connection'
20
+ require 'faraday/rack_builder'
21
+ require 'faraday/parameters'
22
+ require 'faraday/middleware'
23
+ require 'faraday/adapter'
24
+ require 'faraday/request'
25
+ require 'faraday/response'
26
+ require 'faraday/error'
27
+ require 'faraday/file_part'
28
+ require 'faraday/param_part'
29
+
30
+ require 'faraday/em_http'
31
+ require 'faraday/em_synchrony'
32
+ require 'faraday/excon'
33
+ require 'faraday/httpclient'
34
+ require 'faraday/net_http'
35
+ require 'faraday/net_http_persistent'
36
+ require 'faraday/patron'
37
+
9
38
  # This is the main namespace for Faraday.
10
39
  #
11
40
  # It provides methods to create {Connection} objects, and HTTP-related
@@ -19,10 +48,6 @@ require 'faraday/dependency_loader'
19
48
  # conn.get '/'
20
49
  #
21
50
  module Faraday
22
- VERSION = '1.1.0'
23
- METHODS_WITH_QUERY = %w[get head delete trace].freeze
24
- METHODS_WITH_BODY = %w[post put patch].freeze
25
-
26
51
  class << self
27
52
  # The root path that Faraday is being loaded from.
28
53
  #
@@ -107,6 +132,34 @@ module Faraday
107
132
  default_connection.respond_to?(symbol, include_private) || super
108
133
  end
109
134
 
135
+ # @overload default_connection
136
+ # Gets the default connection used for simple scripts.
137
+ # @return [Faraday::Connection] a connection configured with
138
+ # the default_adapter.
139
+ # @overload default_connection=(connection)
140
+ # @param connection [Faraday::Connection]
141
+ # Sets the default {Faraday::Connection} for simple scripts that
142
+ # access the Faraday constant directly, such as
143
+ # <code>Faraday.get "https://faraday.com"</code>.
144
+ def default_connection
145
+ @default_connection ||= Connection.new(default_connection_options)
146
+ end
147
+
148
+ # Gets the default connection options used when calling {Faraday#new}.
149
+ #
150
+ # @return [Faraday::ConnectionOptions]
151
+ def default_connection_options
152
+ @default_connection_options ||= ConnectionOptions.new
153
+ end
154
+
155
+ # Sets the default options used when calling {Faraday#new}.
156
+ #
157
+ # @param options [Hash, Faraday::ConnectionOptions]
158
+ def default_connection_options=(options)
159
+ @default_connection = nil
160
+ @default_connection_options = ConnectionOptions.from(options)
161
+ end
162
+
110
163
  private
111
164
 
112
165
  # Internal: Proxies method calls on the Faraday constant to
@@ -125,42 +178,5 @@ module Faraday
125
178
  self.lib_path = File.expand_path 'faraday', __dir__
126
179
  self.default_adapter = :net_http
127
180
 
128
- # @overload default_connection
129
- # Gets the default connection used for simple scripts.
130
- # @return [Faraday::Connection] a connection configured with
131
- # the default_adapter.
132
- # @overload default_connection=(connection)
133
- # @param connection [Faraday::Connection]
134
- # Sets the default {Faraday::Connection} for simple scripts that
135
- # access the Faraday constant directly, such as
136
- # <code>Faraday.get "https://faraday.com"</code>.
137
- def self.default_connection
138
- @default_connection ||= Connection.new(default_connection_options)
139
- end
140
-
141
- # Gets the default connection options used when calling {Faraday#new}.
142
- #
143
- # @return [Faraday::ConnectionOptions]
144
- def self.default_connection_options
145
- @default_connection_options ||= ConnectionOptions.new
146
- end
147
-
148
- # Sets the default options used when calling {Faraday#new}.
149
- #
150
- # @param options [Hash, Faraday::ConnectionOptions]
151
- def self.default_connection_options=(options)
152
- @default_connection = nil
153
- @default_connection_options = ConnectionOptions.from(options)
154
- end
155
-
156
- unless defined?(::Faraday::Timer)
157
- require 'timeout'
158
- Timer = Timeout
159
- end
160
-
161
- require_libs 'utils', 'options', 'connection', 'rack_builder', 'parameters',
162
- 'middleware', 'adapter', 'request', 'response', 'error',
163
- 'file_part', 'param_part'
164
-
165
181
  require_lib 'autoload' unless ENV['FARADAY_NO_AUTOLOAD']
166
182
  end
@@ -11,18 +11,8 @@ module Faraday
11
11
 
12
12
  register_middleware File.expand_path('adapter', __dir__),
13
13
  test: [:Test, 'test'],
14
- net_http: [:NetHttp, 'net_http'],
15
- net_http_persistent: [
16
- :NetHttpPersistent,
17
- 'net_http_persistent'
18
- ],
19
14
  typhoeus: [:Typhoeus, 'typhoeus'],
20
- patron: [:Patron, 'patron'],
21
- em_synchrony: [:EMSynchrony, 'em_synchrony'],
22
- em_http: [:EMHttp, 'em_http'],
23
- excon: [:Excon, 'excon'],
24
- rack: [:Rack, 'rack'],
25
- httpclient: [:HTTPClient, 'httpclient']
15
+ rack: [:Rack, 'rack']
26
16
 
27
17
  # This module marks an Adapter as supporting parallel requests.
28
18
  module Parallelism
@@ -58,16 +58,9 @@ module Faraday
58
58
  class Adapter
59
59
  extend AutoloadHelper
60
60
  autoload_all 'faraday/adapter',
61
- NetHttp: 'net_http',
62
- NetHttpPersistent: 'net_http_persistent',
63
- EMSynchrony: 'em_synchrony',
64
- EMHttp: 'em_http',
65
61
  Typhoeus: 'typhoeus',
66
- Patron: 'patron',
67
- Excon: 'excon',
68
62
  Test: 'test',
69
- Rack: 'rack',
70
- HTTPClient: 'httpclient'
63
+ Rack: 'rack'
71
64
  end
72
65
 
73
66
  # Request represents a single HTTP request for a Faraday adapter to make.
@@ -73,6 +73,7 @@ module Faraday
73
73
  @options = options.request
74
74
  @ssl = options.ssl
75
75
  @default_parallel_manager = options.parallel_manager
76
+ @manual_proxy = nil
76
77
 
77
78
  @builder = options.builder || begin
78
79
  # pass an empty block to Builder so it doesn't assume default middleware
@@ -419,6 +420,8 @@ module Faraday
419
420
  basic_auth user, password
420
421
  uri.user = uri.password = nil
421
422
  end
423
+
424
+ @proxy = proxy_from_env(url) unless @manual_proxy
422
425
  end
423
426
 
424
427
  # Sets the path prefix and ensures that it always has a leading
@@ -517,11 +520,11 @@ module Faraday
517
520
  # @return [URI]
518
521
  def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
519
522
  url = nil if url.respond_to?(:empty?) && url.empty?
520
- base = url_prefix
523
+ base = url_prefix.dup
521
524
  if url && base.path && base.path !~ %r{/$}
522
- base = base.dup
523
525
  base.path = "#{base.path}/" # ensure trailing slash
524
526
  end
527
+ url = url && URI.parse(url.to_s).opaque ? url.to_s.gsub(':', '%3A') : url
525
528
  uri = url ? base + url : base
526
529
  if params
527
530
  uri.query = params.to_query(params_encoder || options.params_encoder)
@@ -576,7 +579,11 @@ module Faraday
576
579
  case url
577
580
  when String
578
581
  uri = Utils.URI(url)
579
- uri = URI.parse("#{uri.scheme}://#{uri.hostname}").find_proxy
582
+ uri = if uri.host.nil?
583
+ find_default_proxy
584
+ else
585
+ URI.parse("#{uri.scheme}://#{uri.host}").find_proxy
586
+ end
580
587
  when URI
581
588
  uri = url.find_proxy
582
589
  when nil
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruby2_keywords'
4
-
5
3
  module Faraday
6
4
  # DependencyLoader helps Faraday adapters and middleware load dependencies.
7
5
  module DependencyLoader
@@ -15,7 +13,7 @@ module Faraday
15
13
  self.load_error = e
16
14
  end
17
15
 
18
- ruby2_keywords def new(*)
16
+ def new(*)
19
17
  unless loaded?
20
18
  raise "missing dependency for #{self}: #{load_error.message}"
21
19
  end
data/lib/faraday/error.rb CHANGED
@@ -28,6 +28,18 @@ module Faraday
28
28
  %(#<#{self.class}#{inner}>)
29
29
  end
30
30
 
31
+ def response_status
32
+ @response[:status] if @response
33
+ end
34
+
35
+ def response_headers
36
+ @response[:headers] if @response
37
+ end
38
+
39
+ def response_body
40
+ @response[:body] if @response
41
+ end
42
+
31
43
  protected
32
44
 
33
45
  # Pulls out potential parent exception and response hash, storing them in
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ METHODS_WITH_QUERY = %w[get head delete trace].freeze
5
+ METHODS_WITH_BODY = %w[post put patch].freeze
6
+ end
@@ -6,15 +6,25 @@ module Faraday
6
6
  extend MiddlewareRegistry
7
7
  extend DependencyLoader
8
8
 
9
- def initialize(app = nil)
9
+ attr_reader :app, :options
10
+
11
+ def initialize(app = nil, options = {})
10
12
  @app = app
13
+ @options = options
14
+ end
15
+
16
+ def call(env)
17
+ on_request(env) if respond_to?(:on_request)
18
+ app.call(env).on_complete do |environment|
19
+ on_complete(environment) if respond_to?(:on_complete)
20
+ end
11
21
  end
12
22
 
13
23
  def close
14
- if @app.respond_to?(:close)
15
- @app.close
24
+ if app.respond_to?(:close)
25
+ app.close
16
26
  else
17
- warn "#{@app} does not implement \#close!"
27
+ warn "#{app} does not implement \#close!"
18
28
  end
19
29
  end
20
30
  end
@@ -11,6 +11,9 @@ module Faraday
11
11
  def self.from(value)
12
12
  case value
13
13
  when String
14
+ # URIs without a scheme should default to http (like 'example:123').
15
+ # This fixes #1282 and prevents a silent failure in some adapters.
16
+ value = "http://#{value}" unless value.include?('://')
14
17
  value = { uri: Utils.URI(value) }
15
18
  when URI
16
19
  value = { uri: value }
@@ -19,6 +22,7 @@ module Faraday
19
22
  value[:uri] = Utils.URI(uri)
20
23
  end
21
24
  end
25
+
22
26
  super(value)
23
27
  end
24
28