faraday 1.7.1 → 1.8.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: fa04fbf791435b105f33ae2772bfbe8527a24f4b5ec429fe74bd205627fdc39b
4
- data.tar.gz: 5b0be01323591c9628daf113adf8723b2a0396c8c6dbf10440536530def8faf2
3
+ metadata.gz: f6441da03048f7371bd0cb898dd3e27c7be6382c67fc4901883e9dbe9841b56f
4
+ data.tar.gz: 0beb3f2da75282655fc46cd5540de96d5fef259dd35193ec9eb0d3163cc959d2
5
5
  SHA512:
6
- metadata.gz: d7edb34be0a6efc85503a80923b2d109504263cf9042f047dedfdba750f55756ba8d153b23b7774c53f4d6e136a77ab1c2ad82e29099564646bd257d5e311281
7
- data.tar.gz: 05115f5198bbc8de3d4eee3d15c42eefbe7d6ce576f930486c1f4fb1daf79b4223e345adf16e0bc6ef2913d90df73fd069314dfcbeb33fea2ad4108b4ad7ba92
6
+ metadata.gz: 1ab1aa0e0c68c9348d9e180a903f01f2517bd38672fe1bdf056ceab4729e841944173e47dc26aa1b4fe16b2779f1a8102914ed594ea92d08feff6dc944412f0b
7
+ data.tar.gz: bc43fbac427062861e79d5328b60886a5b9c8783f707faa1fcfad064b9c6945f6a4e2a97dbad9ecadc1c1620b5327d651a764962764b7fc86e6d2fbd84ad0b4b
@@ -433,13 +433,18 @@ module Faraday
433
433
  uri.query = nil
434
434
 
435
435
  with_uri_credentials(uri) do |user, password|
436
- basic_auth user, password
436
+ set_basic_auth(user, password)
437
437
  uri.user = uri.password = nil
438
438
  end
439
439
 
440
440
  @proxy = proxy_from_env(url) unless @manual_proxy
441
441
  end
442
442
 
443
+ def set_basic_auth(user, password)
444
+ header = Faraday::Request::BasicAuthentication.header(user, password)
445
+ headers[Faraday::Request::Authorization::KEY] = header
446
+ end
447
+
443
448
  # Sets the path prefix and ensures that it always has a leading
444
449
  # slash.
445
450
  #
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'base64'
4
+
3
5
  module Faraday
4
6
  class Request
5
7
  # Request middleware for the Authorization HTTP header
@@ -13,7 +15,8 @@ module Faraday
13
15
  # @return [String] a header value
14
16
  def self.header(type, token)
15
17
  case token
16
- when String, Symbol
18
+ when String, Symbol, Proc
19
+ token = token.call if token.is_a?(Proc)
17
20
  "#{type} #{token}"
18
21
  when Hash
19
22
  build_hash(type.to_s, token)
@@ -32,6 +35,7 @@ module Faraday
32
35
  comma = ', '
33
36
  values = []
34
37
  hash.each do |key, value|
38
+ value = value.call if value.is_a?(Proc)
35
39
  values << "#{key}=#{value.to_s.inspect}"
36
40
  end
37
41
  "#{type} #{values * comma}"
@@ -39,16 +43,19 @@ module Faraday
39
43
 
40
44
  # @param app [#call]
41
45
  # @param type [String, Symbol] Type of Authorization
42
- # @param token [String, Symbol, Hash] Token value for the Authorization
43
- def initialize(app, type, token)
44
- @header_value = self.class.header(type, token)
46
+ # @param param [String, Symbol, Hash, Proc] parameter to build the Authorization header.
47
+ # This value can be a proc, in which case it will be invoked on each request.
48
+ def initialize(app, type, param)
49
+ @type = type
50
+ @param = param
45
51
  super(app)
46
52
  end
47
53
 
48
54
  # @param env [Faraday::Env]
49
- def call(env)
50
- env.request_headers[KEY] = @header_value unless env.request_headers[KEY]
51
- @app.call(env)
55
+ def on_request(env)
56
+ return if env.request_headers[KEY]
57
+
58
+ env.request_headers[KEY] = self.class.header(@type, @param)
52
59
  end
53
60
  end
54
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '1.7.1'
4
+ VERSION = '1.8.0'
5
5
  end
@@ -84,5 +84,13 @@ RSpec.describe Faraday::Request::Authorization do
84
84
 
85
85
  include_examples 'does not interfere with existing authentication'
86
86
  end
87
+
88
+ context 'when passed a string and a proc' do
89
+ let(:auth_config) { ['Bearer', -> { 'custom_from_proc' }] }
90
+
91
+ it { expect(response.body).to eq('Bearer custom_from_proc') }
92
+
93
+ include_examples 'does not interfere with existing authentication'
94
+ end
87
95
  end
88
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-08-30 00:00:00.000000000 Z
13
+ date: 2021-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday-em_http
@@ -260,7 +260,7 @@ licenses:
260
260
  - MIT
261
261
  metadata:
262
262
  homepage_uri: https://lostisland.github.io/faraday
263
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.7.1
263
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.8.0
264
264
  source_code_uri: https://github.com/lostisland/faraday
265
265
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
266
266
  post_install_message: