excon 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of excon might be problematic. Click here for more details.

@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'excon'
16
- s.version = '0.6.3'
17
- s.date = '2011-05-02'
16
+ s.version = '0.6.4'
17
+ s.date = '2011-07-05'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -91,6 +91,7 @@ Gem::Specification.new do |s|
91
91
  lib/excon/response.rb
92
92
  tests/basic_tests.rb
93
93
  tests/header_tests.rb
94
+ tests/idempotent_tests.rb
94
95
  tests/proxy_tests.rb
95
96
  tests/query_string_tests.rb
96
97
  tests/rackups/basic.ru
@@ -13,7 +13,7 @@ require 'excon/response'
13
13
 
14
14
  module Excon
15
15
  unless const_defined?(:VERSION)
16
- VERSION = '0.6.3'
16
+ VERSION = '0.6.4'
17
17
  end
18
18
 
19
19
  unless const_defined?(:CHUNK_SIZE)
@@ -28,7 +28,7 @@ module Excon
28
28
  attr_reader :ssl_verify_peer
29
29
 
30
30
  # setup ssl defaults based on platform
31
- @ssl_verify_peer = Config::CONFIG['host_os'] !~ /mswin|win32|dos|cygwin|mingw/i
31
+ @ssl_verify_peer = RbConfig::CONFIG['host_os'] !~ /mswin|win32|dos|cygwin|mingw/i
32
32
 
33
33
  # default mocking to off
34
34
  @mock = false
@@ -76,8 +76,16 @@ module Excon
76
76
  if params[:mock]
77
77
  for stub, response in Excon.stubs
78
78
  # all specified non-headers params match and no headers were specified or all specified headers match
79
- if [stub.keys - [:headers]].all? {|key| stub[key] == params[key] } &&
79
+ if (stub.keys - [:headers]).all? {|key| stub[key] == params[key] } &&
80
80
  (!stub.has_key?(:headers) || stub[:headers].keys.all? {|key| stub[:headers][key] == params[:headers][key]})
81
+ if block_given?
82
+ body = response.delete(:body)
83
+ i = 0
84
+ while i < body.length
85
+ yield body[i, CHUNK_SIZE]
86
+ i += CHUNK_SIZE
87
+ end
88
+ end
81
89
  case response
82
90
  when Proc
83
91
  return Excon::Response.new(response.call(params))
@@ -182,7 +190,7 @@ module Excon
182
190
  end
183
191
 
184
192
  rescue => request_error
185
- if params[:idempotent] && [Excon::Errors::SocketError, Excon::Errors::HTTPStatusError].include?(request_error)
193
+ if params[:idempotent] && [Excon::Errors::SocketError, Excon::Errors::HTTPStatusError].any? {|ex| request_error.kind_of? ex }
186
194
  retries_remaining ||= 4
187
195
  retries_remaining -= 1
188
196
  if retries_remaining > 0
@@ -255,7 +263,9 @@ module Excon
255
263
 
256
264
  new_socket.connect
257
265
  # verify connection
258
- new_socket.post_connection_check(@connection[:host])
266
+ if Excon.ssl_verify_peer
267
+ new_socket.post_connection_check(@connection[:host])
268
+ end
259
269
  new_socket
260
270
  end
261
271
 
@@ -8,15 +8,15 @@ Shindo.tests('Excon response header support') do
8
8
 
9
9
  tests('with variable header capitalization') do
10
10
 
11
- tests('response.get_header("content-type")').returns('text/html') do
12
- response.get_header("content-type")
11
+ tests('response.get_header("mixedcase-header")').returns('MixedCase') do
12
+ response.get_header("mixedcase-header")
13
13
  end
14
14
 
15
- tests('response.get_header("custom-header")').returns('foo') do
16
- response.get_header("custom-header")
15
+ tests('response.get_header("uppercase-header")').returns('UPPERCASE') do
16
+ response.get_header("uppercase-header")
17
17
  end
18
18
 
19
- tests('response.get_header("lowercase-header")').returns('bar') do
19
+ tests('response.get_header("lowercase-header")').returns('lowercase') do
20
20
  response.get_header("lowercase-header")
21
21
  end
22
22
 
@@ -24,12 +24,12 @@ Shindo.tests('Excon response header support') do
24
24
 
25
25
  tests('when provided key capitalization varies') do
26
26
 
27
- tests('response.get_header("CONTENT-TYPE")').returns('text/html') do
28
- response.get_header("CONTENT-TYPE")
27
+ tests('response.get_header("MIXEDCASE-HEADER")').returns('MixedCase') do
28
+ response.get_header("MIXEDCASE-HEADER")
29
29
  end
30
30
 
31
- tests('response.get_header("CoNtEnT-TyPe")').returns('text/html') do
32
- response.get_header("CoNtEnT-TyPe")
31
+ tests('response.get_header("MiXeDcAsE-hEaDeR")').returns('MixedCase') do
32
+ response.get_header("MiXeDcAsE-hEaDeR")
33
33
  end
34
34
 
35
35
  end
@@ -0,0 +1,56 @@
1
+ Shindo.tests('Excon request idempotencey') do
2
+ Excon.mock = true
3
+
4
+ tests("Non-idempotent call with an erroring socket").raises(Excon::Errors::SocketError) do
5
+ Excon.stub({:method => :get}) { |params|
6
+ run_count += 1
7
+ if run_count < 4 # First 3 calls fail.
8
+ raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
9
+ else
10
+ {:body => params[:body], :headers => params[:headers], :status => 200}
11
+ end
12
+ }
13
+
14
+ connection = Excon.new('http://127.0.0.1:9292')
15
+ response = connection.request(:method => :get, :path => '/some-path')
16
+ end
17
+
18
+ Excon.stubs.pop
19
+
20
+ tests("Idempotent request with socket erroring first 3 times").returns(200) do
21
+ run_count = 0
22
+ Excon.stub({:method => :get}) { |params|
23
+ run_count += 1
24
+ if run_count <= 3 # First 3 calls fail.
25
+ raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
26
+ else
27
+ {:body => params[:body], :headers => params[:headers], :status => 200}
28
+ end
29
+ }
30
+
31
+ connection = Excon.new('http://127.0.0.1:9292')
32
+ response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
33
+ response.status
34
+ end
35
+
36
+ Excon.stubs.pop
37
+
38
+ tests("Idempotent request with socket erroring first 5 times").raises(Excon::Errors::SocketError) do
39
+ run_count = 0
40
+ Excon.stub({:method => :get}) { |params|
41
+ run_count += 1
42
+ if run_count <= 5 # First 5 calls fail.
43
+ raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
44
+ else
45
+ {:body => params[:body], :headers => params[:headers], :status => 200}
46
+ end
47
+ }
48
+
49
+ connection = Excon.new('http://127.0.0.1:9292')
50
+ response = connection.request(:method => :get, :idempotent => true, :path => '/some-path')
51
+ response.status
52
+ end
53
+
54
+ Excon.stubs.pop
55
+ Excon.mock = false
56
+ end
@@ -3,9 +3,9 @@ require 'sinatra'
3
3
  class App < Sinatra::Base
4
4
  get('/foo') do
5
5
  headers(
6
- "Content-Type" => 'text/html',
7
- "CUSTOM-HEADER" => 'foo',
8
- "lowercase-header" => 'bar'
6
+ "MixedCase-Header" => 'MixedCase',
7
+ "UPPERCASE-HEADER" => 'UPPERCASE',
8
+ "lowercase-header" => 'lowercase'
9
9
  )
10
10
  'primary content'
11
11
  end
@@ -60,6 +60,24 @@ Shindo.tests('Excon stubs') do
60
60
 
61
61
  end
62
62
 
63
+ tests("mismatched stub").raises(Excon::Errors::StubNotFound) do
64
+ Excon.stub({:method => :post}, {:body => 'body'})
65
+ Excon.get('http://127.0.0.1:9292/')
66
+ end
67
+
68
+ tests("stub({}, {:body => 'x' * (Excon::CHUNK_SIZE + 1)})") do
69
+ connection = Excon.new('http://127.0.0.1:9292')
70
+ Excon.stub({}, {:body => 'x' * (Excon::CHUNK_SIZE + 1)})
71
+
72
+ test("with block") do
73
+ chunks = []
74
+ response = connection.request(:method => :get, :path => '/content-length/100') do |chunk|
75
+ chunks << chunk
76
+ end
77
+ chunks == ['x' * Excon::CHUNK_SIZE, 'x']
78
+ end
79
+ end
80
+
63
81
  Excon.mock = false
64
82
 
65
83
  tests('mock = false') do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - geemus (Wesley Beary)
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-02 00:00:00 Z
18
+ date: 2011-07-05 00:00:00 -05:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: open4
@@ -112,6 +113,7 @@ files:
112
113
  - lib/excon/response.rb
113
114
  - tests/basic_tests.rb
114
115
  - tests/header_tests.rb
116
+ - tests/idempotent_tests.rb
115
117
  - tests/proxy_tests.rb
116
118
  - tests/query_string_tests.rb
117
119
  - tests/rackups/basic.ru
@@ -122,6 +124,7 @@ files:
122
124
  - tests/stub_tests.rb
123
125
  - tests/test_helper.rb
124
126
  - tests/thread_safety_tests.rb
127
+ has_rdoc: true
125
128
  homepage: https://github.com/geemus/excon
126
129
  licenses: []
127
130
 
@@ -151,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
154
  requirements: []
152
155
 
153
156
  rubyforge_project: excon
154
- rubygems_version: 1.7.2
157
+ rubygems_version: 1.4.1
155
158
  signing_key:
156
159
  specification_version: 2
157
160
  summary: speed, persistence, http(s)