faraday-excon 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c003d4288f7c9b83abb71ff8fcf34858f049c2b6fc531f53720ff6eec888dd7d
4
- data.tar.gz: adb5e1c19a317597e293e2f67e5dc9eb9c5c984381078f5b8f587bba6dda862f
3
+ metadata.gz: 48cc25dbe1f1b2758a18d7b632862a0b925c41dcf60b85017571af0b1ae9e5c8
4
+ data.tar.gz: 31f11d707f4d986908b2a0d92203843c563a40c49c0b363f02180747f8b85c4c
5
5
  SHA512:
6
- metadata.gz: 91ace0a8a95b318c587c023197833fa4a1df61ebc7deaddb733a8a638f6c0abc1bda669ad9b0c94b9053b46baf27ef1ca0d2e29b103b9d28fb57e8770c225968
7
- data.tar.gz: fa06ea79333d4a0cc662dfc142a594de4319a82a8e5601140c2af2676795bc8c8e165827e285e3a2008b03ef6c0a3c1124b6f6a924c560486015ee4ad65c6f39
6
+ metadata.gz: cd71d9c447b9fa17960250bba74842d173491be820aa1c2713fa28cc78a3558d11d5362549e2a7593132b353a1aca9d40dcc1864ac2bc41acdf0b798e6f86e39
7
+ data.tar.gz: 983de5b151300ac67cd7ed09df531353bea392e49c740087e4810444cbe6aa7799ef43c679b25c1db681ca8b7e8d381e6fd232c1af3f9cf15ae9588c07e70e99
data/README.md CHANGED
@@ -29,6 +29,14 @@ conn = Faraday.new(...) do |f|
29
29
  end
30
30
  ```
31
31
 
32
+ Passing connection options:
33
+ ```ruby
34
+ conn = Faraday.new(...) do |f|
35
+ # Will keep the connection memoized within the adapter, and rely that flag to excon
36
+ f.adapter :excon, persistent: true
37
+ end
38
+ ```
39
+
32
40
  ## Development
33
41
 
34
42
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -5,14 +5,26 @@ module Faraday
5
5
  # Excon adapter.
6
6
  class Excon < Faraday::Adapter
7
7
  def build_connection(env)
8
+ if @connection_options[:persistent]
9
+ return @connection if defined? @connection
10
+ end
8
11
  opts = opts_from_env(env)
9
- ::Excon.new(env[:url].to_s, opts.merge(@connection_options))
12
+
13
+ # remove path & query when creating connection
14
+ # because if it is persistent, it can re-use the conn
15
+ url = env[:url].dup
16
+ url.path = ''
17
+ url.query = nil
18
+
19
+ @connection = ::Excon.new(url.to_s, opts.merge(@connection_options))
10
20
  end
11
21
 
12
22
  def call(env)
13
23
  super
14
24
 
15
25
  req_opts = {
26
+ path: env[:url].path,
27
+ query: env[:url].query,
16
28
  method: env[:method].to_s.upcase,
17
29
  headers: env[:request_headers],
18
30
  body: read_body(env)
@@ -26,11 +38,22 @@ module Faraday
26
38
  end
27
39
  end
28
40
 
29
- resp = connection(env) { |http| http.request(req_opts) }
41
+ resp = connect_and_request(env, req_opts)
30
42
  save_response(env, resp.status.to_i, resp.body, resp.headers,
31
43
  resp.reason_phrase)
32
44
 
33
45
  @app.call(env)
46
+ end
47
+
48
+ # TODO: support streaming requests
49
+ def read_body(env)
50
+ env[:body].respond_to?(:read) ? env[:body].read : env[:body]
51
+ end
52
+
53
+ private
54
+
55
+ def connect_and_request(env, req_opts)
56
+ connection(env) { |http| http.request(req_opts) }
34
57
  rescue ::Excon::Errors::SocketError => e
35
58
  raise Faraday::TimeoutError, e if e.message.match?(/\btimeout\b/)
36
59
 
@@ -41,13 +64,6 @@ module Faraday
41
64
  raise Faraday::TimeoutError, e
42
65
  end
43
66
 
44
- # TODO: support streaming requests
45
- def read_body(env)
46
- env[:body].respond_to?(:read) ? env[:body].read : env[:body]
47
- end
48
-
49
- private
50
-
51
67
  def opts_from_env(env)
52
68
  opts = {}
53
69
  amend_opts_with_ssl!(opts, env[:ssl]) if needs_ssl_settings?(env)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module Excon
5
- VERSION = '2.0.0'
5
+ VERSION = '2.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-excon
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@iMacTia"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-10 00:00:00.000000000 Z
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.0.alpha.pre.2
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.0.alpha.pre.2
40
+ version: '2.0'
41
41
  description: Faraday adapter for Excon
42
42
  email:
43
43
  - giuffrida.mattia@gmail.com
@@ -56,7 +56,7 @@ licenses:
56
56
  metadata:
57
57
  homepage_uri: https://github.com/lostisland/faraday-excon
58
58
  source_code_uri: https://github.com/lostisland/faraday-excon
59
- changelog_uri: https://github.com/lostisland/faraday-excon/releases/tag/v2.0.0
59
+ changelog_uri: https://github.com/lostisland/faraday-excon/releases/tag/v2.1.0
60
60
  post_install_message:
61
61
  rdoc_options: []
62
62
  require_paths: