faraday 0.8.10 → 0.8.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faraday.rb +1 -1
- data/lib/faraday/adapter/em_synchrony.rb +6 -0
- data/lib/faraday/adapter/excon.rb +1 -0
- data/lib/faraday/connection.rb +6 -1
- data/lib/faraday/request/retry.rb +2 -0
- data/lib/faraday/utils.rb +13 -0
- data/script/package +7 -0
- data/script/release +14 -0
- data/test/adapters/integration.rb +3 -1
- data/test/connection_test.rb +19 -1
- data/test/middleware/retry_test.rb +32 -1
- data/test/utils_test.rb +8 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 431792ff21fb498eb658855f87503d2081869616
|
4
|
+
data.tar.gz: c6b3a7f9c1a9f7a4a60eff2236b882dbd812eab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8855727969169984a104ba02c2ed27b4a86fb7d3a698fe6f5932c4858cb5e4f5eba9251d3742cb8d999b654f89ff2d073228738998f3199ae104e9e9883bd031
|
7
|
+
data.tar.gz: eda459cc1abe00450f0d48dab3b069544dd414001faf9be231e2215fa81efced7496a99a2baa6502f1d7bbe162f6b41f415cdef1cd9ce935a9de8752749997a3
|
data/lib/faraday.rb
CHANGED
data/lib/faraday/connection.rb
CHANGED
@@ -307,7 +307,12 @@ module Faraday
|
|
307
307
|
end
|
308
308
|
|
309
309
|
def dup
|
310
|
-
self.class.new(build_url(''),
|
310
|
+
self.class.new(build_url(''),
|
311
|
+
:headers => headers.dup,
|
312
|
+
:params => params.dup,
|
313
|
+
:builder => builder.dup,
|
314
|
+
:ssl => ssl.dup,
|
315
|
+
:request => options.dup)
|
311
316
|
end
|
312
317
|
|
313
318
|
# Internal: Yields username and password extracted from a URI if they both exist.
|
data/lib/faraday/utils.rb
CHANGED
@@ -12,6 +12,12 @@ module Faraday
|
|
12
12
|
self.update hash
|
13
13
|
end
|
14
14
|
|
15
|
+
# on dup/clone, we need to duplicate @names hash
|
16
|
+
def initialize_copy(other)
|
17
|
+
super
|
18
|
+
@names = other.names.dup
|
19
|
+
end
|
20
|
+
|
15
21
|
# symbol -> string mapper + cache
|
16
22
|
KeyMap = Hash.new do |map, key|
|
17
23
|
map[key] = if key.respond_to?(:to_str) then key
|
@@ -65,6 +71,7 @@ module Faraday
|
|
65
71
|
|
66
72
|
def replace(other)
|
67
73
|
clear
|
74
|
+
@names.clear
|
68
75
|
self.update other
|
69
76
|
self
|
70
77
|
end
|
@@ -83,6 +90,12 @@ module Faraday
|
|
83
90
|
end
|
84
91
|
}
|
85
92
|
end
|
93
|
+
|
94
|
+
protected
|
95
|
+
|
96
|
+
def names
|
97
|
+
@names
|
98
|
+
end
|
86
99
|
end
|
87
100
|
|
88
101
|
# hash with stringified keys
|
data/script/package
ADDED
data/script/release
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# Usage: script/release
|
3
|
+
# Build the package, tag a commit, push it to origin, and then release the
|
4
|
+
# package publicly.
|
5
|
+
|
6
|
+
set -e
|
7
|
+
|
8
|
+
version="$(script/package | grep Version: | awk '{print $2}')"
|
9
|
+
[ -n "$version" ] || exit 1
|
10
|
+
|
11
|
+
git commit -a -m "faraday $version"
|
12
|
+
git tag "v${version}"
|
13
|
+
git push origin "v${version}" HEAD
|
14
|
+
gem push pkg/*-${version}.gem
|
@@ -194,8 +194,10 @@ module Adapters
|
|
194
194
|
conn.get '/echo'
|
195
195
|
end
|
196
196
|
|
197
|
-
unless self.class.ssl_mode? && self.class.jruby?
|
197
|
+
unless self.class.ssl_mode? && (self.class.jruby? ||
|
198
|
+
adapter == :em_http || adapter == :em_synchrony)
|
198
199
|
# JRuby raises "End of file reached" which cannot be distinguished from a 407
|
200
|
+
# EM raises "connection closed by server" due to https://github.com/igrigorik/em-socksify/pull/19
|
199
201
|
assert_equal %{407 "Proxy Authentication Required "}, err.message
|
200
202
|
end
|
201
203
|
end
|
data/test/connection_test.rb
CHANGED
@@ -212,6 +212,20 @@ class TestConnection < Faraday::TestCase
|
|
212
212
|
assert_equal '/sake.html', uri.path
|
213
213
|
end
|
214
214
|
|
215
|
+
def test_request_header_change_does_not_modify_connection_header
|
216
|
+
connection = Faraday.new(:url => "https://asushi.com/sake.html")
|
217
|
+
connection.headers = { "Authorization"=>"token abc123" }
|
218
|
+
|
219
|
+
request = connection.build_request(:get)
|
220
|
+
request.headers.delete("Authorization")
|
221
|
+
|
222
|
+
assert_equal connection.headers.keys.sort, ["Authorization"]
|
223
|
+
assert connection.headers.include?("Authorization")
|
224
|
+
|
225
|
+
assert_equal request.headers.keys.sort, []
|
226
|
+
assert !request.headers.include?("Authorization")
|
227
|
+
end
|
228
|
+
|
215
229
|
def test_proxy_accepts_string
|
216
230
|
with_env 'http_proxy', "http://duncan.proxy.com:80" do
|
217
231
|
conn = Faraday::Connection.new
|
@@ -303,7 +317,8 @@ class TestConnection < Faraday::TestCase
|
|
303
317
|
conn = Faraday::Connection.new 'http://sushi.com/foo',
|
304
318
|
:ssl => { :verify => :none },
|
305
319
|
:headers => {'content-type' => 'text/plain'},
|
306
|
-
:params => {'a'=>'1'}
|
320
|
+
:params => {'a'=>'1'},
|
321
|
+
:request => {:timeout => 5}
|
307
322
|
|
308
323
|
other = conn.dup
|
309
324
|
|
@@ -314,11 +329,14 @@ class TestConnection < Faraday::TestCase
|
|
314
329
|
other.basic_auth('', '')
|
315
330
|
other.headers['content-length'] = 12
|
316
331
|
other.params['b'] = '2'
|
332
|
+
other.options[:open_timeout] = 10
|
317
333
|
|
318
334
|
assert_equal 2, other.builder.handlers.size
|
319
335
|
assert_equal 2, conn.builder.handlers.size
|
320
336
|
assert !conn.headers.key?('content-length')
|
321
337
|
assert !conn.params.key?('b')
|
338
|
+
assert_equal 5, other.options[:timeout]
|
339
|
+
assert_nil conn.options[:open_timeout]
|
322
340
|
end
|
323
341
|
|
324
342
|
def test_init_with_block
|
@@ -6,20 +6,51 @@ module Middleware
|
|
6
6
|
@stubs = Faraday::Adapter::Test::Stubs.new
|
7
7
|
@conn = Faraday.new do |b|
|
8
8
|
b.request :retry, 2
|
9
|
+
b.use ContentValidator
|
9
10
|
b.adapter :test, @stubs
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
14
|
+
ContentValidator = Struct.new(:app) do
|
15
|
+
def call(env)
|
16
|
+
response = app.call(env)
|
17
|
+
type = response[:content_type]
|
18
|
+
raise "wrong content-type: %p" % type unless type == "application/json"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
13
22
|
def test_retries
|
14
23
|
times_called = 0
|
15
24
|
|
16
25
|
@stubs.post("/echo") do
|
17
26
|
times_called += 1
|
18
|
-
|
27
|
+
[200, {}, "hello"]
|
19
28
|
end
|
20
29
|
|
21
30
|
@conn.post("/echo") rescue nil
|
22
31
|
assert_equal times_called, 3
|
23
32
|
end
|
33
|
+
|
34
|
+
def test_retry_with_body
|
35
|
+
times_called = 0
|
36
|
+
bodies_received = []
|
37
|
+
|
38
|
+
@stubs.post("/echo") do |env|
|
39
|
+
times_called += 1
|
40
|
+
bodies_received << env[:body]
|
41
|
+
if times_called < 2
|
42
|
+
[200, {"Content-type" => "text/plain"}, "hello"]
|
43
|
+
else
|
44
|
+
[200, {"Content-type" => "application/json"}, '{"message": "hello"}']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
body = {:foo => "bar"}
|
49
|
+
@conn.post("/echo", body)
|
50
|
+
|
51
|
+
assert_equal times_called, 2
|
52
|
+
assert_same body, bodies_received[0]
|
53
|
+
assert_same body, bodies_received[1]
|
54
|
+
end
|
24
55
|
end
|
25
56
|
end
|
data/test/utils_test.rb
CHANGED
@@ -18,5 +18,13 @@ class TestUtils < Faraday::TestCase
|
|
18
18
|
assert_equal '%2432%2C000.00', Faraday::Utils.escape(str)
|
19
19
|
end
|
20
20
|
|
21
|
+
def test_replace_header_hash
|
22
|
+
headers = Faraday::Utils::Headers.new('authorization' => 't0ps3cr3t!')
|
23
|
+
assert headers.include?('authorization')
|
24
|
+
|
25
|
+
headers.replace({'content-type' => 'text/plain'})
|
26
|
+
|
27
|
+
assert !headers.include?('authorization')
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Olson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
@@ -63,7 +63,9 @@ files:
|
|
63
63
|
- lib/faraday/upload_io.rb
|
64
64
|
- lib/faraday/utils.rb
|
65
65
|
- script/generate_certs
|
66
|
+
- script/package
|
66
67
|
- script/proxy-server
|
68
|
+
- script/release
|
67
69
|
- script/server
|
68
70
|
- script/test
|
69
71
|
- test/adapters/default_test.rb
|
@@ -111,8 +113,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
113
|
version: 1.3.6
|
112
114
|
requirements: []
|
113
115
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.2.
|
116
|
+
rubygems_version: 2.2.3
|
115
117
|
signing_key:
|
116
118
|
specification_version: 2
|
117
119
|
summary: HTTP/REST API client library.
|
118
120
|
test_files: []
|
121
|
+
has_rdoc:
|