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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d43934c707a0fca6c31ccda1806c65af0c144b79
4
- data.tar.gz: b30578af99d6349a20003d39441d66ee14f6992a
3
+ metadata.gz: 431792ff21fb498eb658855f87503d2081869616
4
+ data.tar.gz: c6b3a7f9c1a9f7a4a60eff2236b882dbd812eab4
5
5
  SHA512:
6
- metadata.gz: 8ad0e359c5aac602dd49f1c5c74a3009f0b42b5b42948f86cac8fd510603d46d75ab24ed30c4795903fc0b74cb0a828def6287f3dd097a37ec0e30ab673d2ca5
7
- data.tar.gz: c713445a9a4efae7891594e8bb8bd7835ca32333db26df84d1e27f5eb8e80481683cea59a40afc42f31e9b4e6419605748410cf85cb75f598534e94870ea8219
6
+ metadata.gz: 8855727969169984a104ba02c2ed27b4a86fb7d3a698fe6f5932c4858cb5e4f5eba9251d3742cb8d999b654f89ff2d073228738998f3199ae104e9e9883bd031
7
+ data.tar.gz: eda459cc1abe00450f0d48dab3b069544dd414001faf9be231e2215fa81efced7496a99a2baa6502f1d7bbe162f6b41f415cdef1cd9ce935a9de8752749997a3
@@ -1,5 +1,5 @@
1
1
  module Faraday
2
- VERSION = "0.8.10"
2
+ VERSION = "0.8.11"
3
3
 
4
4
  class << self
5
5
  attr_accessor :root_path, :lib_path
@@ -70,6 +70,12 @@ module Faraday
70
70
  else
71
71
  raise Error::ConnectionFailed, err
72
72
  end
73
+ rescue RuntimeError => err
74
+ if err.message == "connection closed by server"
75
+ raise Error::ConnectionFailed, err
76
+ else
77
+ raise
78
+ end
73
79
  end
74
80
  end
75
81
  end
@@ -32,6 +32,7 @@ module Faraday
32
32
  if req[:proxy]
33
33
  opts[:proxy] = {
34
34
  :host => req[:proxy][:uri].host,
35
+ :hostname => req[:proxy][:uri].hostname,
35
36
  :port => req[:proxy][:uri].port,
36
37
  :scheme => req[:proxy][:uri].scheme,
37
38
  :user => req[:proxy][:user],
@@ -307,7 +307,12 @@ module Faraday
307
307
  end
308
308
 
309
309
  def dup
310
- self.class.new(build_url(''), :headers => headers.dup, :params => params.dup, :builder => builder.dup, :ssl => ssl.dup)
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.
@@ -7,7 +7,9 @@ module Faraday
7
7
 
8
8
  def call(env)
9
9
  retries = @retries
10
+ request_body = env[:body]
10
11
  begin
12
+ env[:body] = request_body # after failure env[:body] is set to the response body
11
13
  @app.call(env)
12
14
  rescue StandardError, Timeout::Error
13
15
  if retries > 0
@@ -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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ # Usage: script/gem
3
+ # Updates the gemspec and builds a new gem in the pkg directory.
4
+
5
+ mkdir -p pkg
6
+ gem build *.gemspec
7
+ mv *.gem pkg
@@ -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
@@ -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
- raise "Error occurred"
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
@@ -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.10
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-08-21 00:00:00.000000000 Z
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.0
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: