faraday 2.0.0.alpha.pre.2 → 2.0.0.alpha.pre.3
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 +4 -4
- data/lib/faraday/connection.rb +1 -1
- data/lib/faraday/utils.rb +1 -1
- data/lib/faraday/version.rb +1 -1
- data/lib/faraday.rb +1 -1
- data/spec/faraday/connection_spec.rb +21 -0
- data/spec/faraday/utils_spec.rb +61 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c5ab8c9cafcd2690a2ea370814f080f0a085e666377048166868b84a9b3fb7e
|
4
|
+
data.tar.gz: 399207b7f32439dae2f9ad22bf839479e3cf715001f6b8d8a8fb8f88bb1f565d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a1b9107707c0f2ad30040885cd0037bf5ea64f3035e28b2cf4c8f0304de8b3acbc9217d6c77b0889a0603909dfaf87a9c54108a0a65e34291d13b69eae8efec
|
7
|
+
data.tar.gz: 74083d46a172455f40fd28151b806678c4d8f404508f2b25e2a8eb7b08c025a870565467fd5dff2420e2f1ebb01327b09d5519877770f46e0ea7d83c30c15a13
|
data/lib/faraday/connection.rb
CHANGED
data/lib/faraday/utils.rb
CHANGED
@@ -101,7 +101,7 @@ module Faraday
|
|
101
101
|
# Recursive hash update
|
102
102
|
def deep_merge!(target, hash)
|
103
103
|
hash.each do |key, value|
|
104
|
-
target[key] = if value.is_a?(Hash) && target[key].is_a?(Hash)
|
104
|
+
target[key] = if value.is_a?(Hash) && (target[key].is_a?(Hash) || target[key].is_a?(Options))
|
105
105
|
deep_merge(target[key], value)
|
106
106
|
else
|
107
107
|
value
|
data/lib/faraday/version.rb
CHANGED
data/lib/faraday.rb
CHANGED
@@ -92,7 +92,7 @@ module Faraday
|
|
92
92
|
# params: { page: 1 }
|
93
93
|
# # => Faraday::Connection to http://faraday.com?page=1
|
94
94
|
def new(url = nil, options = {}, &block)
|
95
|
-
options =
|
95
|
+
options = Utils.deep_merge(default_connection_options, options)
|
96
96
|
Faraday::Connection.new(url, options, &block)
|
97
97
|
end
|
98
98
|
|
@@ -639,6 +639,27 @@ RSpec.describe Faraday::Connection do
|
|
639
639
|
|
640
640
|
it_behaves_like 'default connection options'
|
641
641
|
end
|
642
|
+
|
643
|
+
context 'preserving a user_agent assigned via default_conncetion_options' do
|
644
|
+
around do |example|
|
645
|
+
old = Faraday.default_connection_options
|
646
|
+
Faraday.default_connection_options = { headers: { user_agent: 'My Agent 1.2' } }
|
647
|
+
example.run
|
648
|
+
Faraday.default_connection_options = old
|
649
|
+
end
|
650
|
+
|
651
|
+
context 'when url is a Hash' do
|
652
|
+
let(:conn) { Faraday.new(url: 'http://example.co', headers: { 'CustomHeader' => 'CustomValue' }) }
|
653
|
+
|
654
|
+
it { expect(conn.headers).to eq('CustomHeader' => 'CustomValue', 'User-Agent' => 'My Agent 1.2') }
|
655
|
+
end
|
656
|
+
|
657
|
+
context 'when url is a String' do
|
658
|
+
let(:conn) { Faraday.new('http://example.co', headers: { 'CustomHeader' => 'CustomValue' }) }
|
659
|
+
|
660
|
+
it { expect(conn.headers).to eq('CustomHeader' => 'CustomValue', 'User-Agent' => 'My Agent 1.2') }
|
661
|
+
end
|
662
|
+
end
|
642
663
|
end
|
643
664
|
|
644
665
|
describe 'request params' do
|
data/spec/faraday/utils_spec.rb
CHANGED
@@ -53,4 +53,65 @@ RSpec.describe Faraday::Utils do
|
|
53
53
|
expect(headers).not_to have_key('authorization')
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe '.deep_merge!' do
|
58
|
+
let(:connection_options) { Faraday::ConnectionOptions.new }
|
59
|
+
let(:url) do
|
60
|
+
{
|
61
|
+
url: 'http://example.com/abc',
|
62
|
+
headers: { 'Mime-Version' => '1.0' },
|
63
|
+
request: { oauth: { consumer_key: 'anonymous' } },
|
64
|
+
ssl: { version: '2' }
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'recursively merges the headers' do
|
69
|
+
connection_options.headers = { user_agent: 'My Agent 1.0' }
|
70
|
+
deep_merge = Faraday::Utils.deep_merge!(connection_options, url)
|
71
|
+
|
72
|
+
expect(deep_merge.headers).to eq('Mime-Version' => '1.0', user_agent: 'My Agent 1.0')
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when a target hash has an Options Struct value' do
|
76
|
+
let(:request) do
|
77
|
+
{
|
78
|
+
params_encoder: nil,
|
79
|
+
proxy: nil,
|
80
|
+
bind: nil,
|
81
|
+
timeout: nil,
|
82
|
+
open_timeout: nil,
|
83
|
+
read_timeout: nil,
|
84
|
+
write_timeout: nil,
|
85
|
+
boundary: nil,
|
86
|
+
oauth: { consumer_key: 'anonymous' },
|
87
|
+
context: nil,
|
88
|
+
on_data: nil
|
89
|
+
}
|
90
|
+
end
|
91
|
+
let(:ssl) do
|
92
|
+
{
|
93
|
+
verify: nil,
|
94
|
+
ca_file: nil,
|
95
|
+
ca_path: nil,
|
96
|
+
verify_mode: nil,
|
97
|
+
cert_store: nil,
|
98
|
+
client_cert: nil,
|
99
|
+
client_key: nil,
|
100
|
+
certificate: nil,
|
101
|
+
private_key: nil,
|
102
|
+
verify_depth: nil,
|
103
|
+
version: '2',
|
104
|
+
min_version: nil,
|
105
|
+
max_version: nil
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'does not overwrite an Options Struct value' do
|
110
|
+
deep_merge = Faraday::Utils.deep_merge!(connection_options, url)
|
111
|
+
|
112
|
+
expect(deep_merge.request.to_h).to eq(request)
|
113
|
+
expect(deep_merge.ssl.to_h).to eq(ssl)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
56
117
|
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: 2.0.0.alpha.pre.
|
4
|
+
version: 2.0.0.alpha.pre.3
|
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-
|
13
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multipart-post
|
@@ -137,7 +137,7 @@ licenses:
|
|
137
137
|
- MIT
|
138
138
|
metadata:
|
139
139
|
homepage_uri: https://lostisland.github.io/faraday
|
140
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.0.0.alpha.pre.
|
140
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.0.0.alpha.pre.3
|
141
141
|
source_code_uri: https://github.com/lostisland/faraday
|
142
142
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
143
143
|
post_install_message:
|