faraday 1.7.2 → 1.8.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: dc552d61adb1522a8fad137e999bf05ca2bab8f23da090e832023a407482e2be
4
- data.tar.gz: 90dc970e1e03002fc8f49ca3cd07aeb9636b03b6ebd2fc2fe856c0f38661aa3f
3
+ metadata.gz: f6441da03048f7371bd0cb898dd3e27c7be6382c67fc4901883e9dbe9841b56f
4
+ data.tar.gz: 0beb3f2da75282655fc46cd5540de96d5fef259dd35193ec9eb0d3163cc959d2
5
5
  SHA512:
6
- metadata.gz: ef70a25de820defbfa52dbc6da6abc01dda7b190326fdf637eaaa3d988b5fefba726ccb3813b974367a7c1a3e00e748dcac44018ba9f2bdd172591dc83441e58
7
- data.tar.gz: ddcaf2f3d6bbf55d713a661a429073c4d4230c5723281765e64931cc24a5f17a8ffc81d9cddfc1ca43f759474346993c980797d3978016912a5eb8885677b737
6
+ metadata.gz: 1ab1aa0e0c68c9348d9e180a903f01f2517bd38672fe1bdf056ceab4729e841944173e47dc26aa1b4fe16b2779f1a8102914ed594ea92d08feff6dc944412f0b
7
+ data.tar.gz: bc43fbac427062861e79d5328b60886a5b9c8783f707faa1fcfad064b9c6945f6a4e2a97dbad9ecadc1c1620b5327d651a764962764b7fc86e6d2fbd84ad0b4b
@@ -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.2'
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.2
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-09-13 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.2
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: