excon 0.39.6 → 0.40.0

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.

checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2M2NWI4NmRiODMxZTgzNDk2NjE2MjBlYjk2Yjc0MjlkMDBmNWFkOQ==
4
+ ODlkNWVjNzM5NDE2MzY0NzhmYWRlYzJjNDYzMWI3NTE0ZDQ4MWJlNg==
5
5
  data.tar.gz: !binary |-
6
- MWJjMTRjZjg0MjYwOWQ1OWMzY2Q3ODRkMTk2MGQ0N2Q0ODQ2NjRiNQ==
6
+ ZGFiN2VhOTJiNDRjMGVhYWE3YjU0NjIyYjZiZTg3YWIyMmU0ZThjMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODE4MmIwY2FmNGRhYTVmODI2MjA1OWI1OTQ3ZTI2Yjc3YzZhZjZjZDFhNTQ0
10
- ZTM5ZTMyYjc3NzA1NDk4NjMxNzdiMTJmNDIyOWY2MjI0OTdkY2E4OGRhMDlk
11
- NWM0YjA0YTJmN2Y0MTI1MTc3MDNjZmVmNWY4YTBmMGI5ZDBmMDM=
9
+ NDMxNjEzM2M1YjhmNmE4MTNjMjljNDkzNWMyZjUxNmIyYWE2ZGFiYmQyMDBk
10
+ MWQzZTZlMDE1YzE3MmEwZWQzMjQyMGFiMWViZjhlMzlmZjI0M2IwMDE5YmI4
11
+ ODg4MjczZDczYjNhZDhlMzA5MTAwNTlkNjZhMzk1Njc4ZDgzYjc=
12
12
  data.tar.gz: !binary |-
13
- ZGMwM2M3ZjQ1MTBiOTY2ZjUwY2U5MzVjYzcyMTA4ZjAwYWVmNTQwNDQ4ZTZh
14
- OTU0M2NiMzUxNDYwNWIyNzk0YThmY2U3NTY2OGFkOTQ2NmUwNjI3YjBiMTJl
15
- NTc0ZTUzMDE0ZDA0ZTk3M2ZkNzQ2NTRkY2Y2ZmI0MDA4OGY5ZTI=
13
+ ZDk4MTk3ZmYxYjJkY2E5YTFhNWFjMWUxYmEyYTA5MjllNWVhZmY1NjEwOTU0
14
+ YzUyYjY1NDcwZmYyZTEwNzQ0M2RmZWY3YjE1YjlkYTk2NmU3NGYyOGFmNTNh
15
+ YWFkYTc1OTkxYTk0NTI2MzFjZjFmM2MwMDg0Mzc5OTM0YzE3YmQ=
@@ -37,6 +37,7 @@
37
37
  * Jonathan Dance <github@wuputah.com>
38
38
  * Jonathan Dance <jd@wuputah.com>
39
39
  * Jonathan Roes <jroes@jroes.net>
40
+ * Joshua Gross <joshua@surfeasy.com>
40
41
  * Joshua Mckinney <joshmckin@gmail.com>
41
42
  * Joshua Napoli <jnapoli@swipely-napoli.home>
42
43
  * Joshua Napoli <jnapoli@swipely-napoli.local>
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- excon (0.39.6)
4
+ excon (0.40.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,3 +1,10 @@
1
+ 0.40.0 10/06/2014
2
+ =================
3
+
4
+ fix support for specifying ssl_ca_path
5
+ more consistent response_block/response.body behavior for mocks
6
+ add support for proxies running on unix domain sockets
7
+
1
8
  0.39.6 09/22/2014
2
9
  =================
3
10
 
@@ -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.39.6'
17
- s.date = '2014-09-22'
16
+ s.version = '0.40.0'
17
+ s.date = '2014-10-06'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -179,8 +179,10 @@ module Excon
179
179
  end
180
180
 
181
181
  def response_call(datum)
182
+ # ensure response_block is yielded to and body is empty from middlewares
182
183
  if datum.has_key?(:response_block) && !datum[:response][:body].empty?
183
184
  response_body = datum[:response][:body].dup
185
+ datum[:response][:body] = ''
184
186
  content_length = remaining = response_body.bytesize
185
187
  while remaining > 0
186
188
  datum[:response_block].call(response_body.slice!(0, [datum[:chunk_size], remaining].min), [remaining - datum[:chunk_size], 0].max, content_length)
@@ -371,10 +373,11 @@ module Excon
371
373
  end
372
374
 
373
375
  def socket
374
- sockets[@socket_key] ||= if @data[:scheme] == HTTPS
375
- Excon::SSLSocket.new(@data)
376
- elsif @data[:scheme] == UNIX
376
+ unix_proxy = @data[:proxy] ? @data[:proxy][:scheme] == UNIX : false
377
+ sockets[@socket_key] ||= if @data[:scheme] == UNIX || unix_proxy
377
378
  Excon::UnixSocket.new(@data)
379
+ elsif @data[:scheme] == HTTPS
380
+ Excon::SSLSocket.new(@data)
378
381
  else
379
382
  Excon::Socket.new(@data)
380
383
  end
@@ -405,11 +408,10 @@ module Excon
405
408
  # no processing needed
406
409
  when String
407
410
  uri = URI.parse(@data[:proxy])
408
- unless uri.host && uri.port && uri.scheme
409
- raise Excon::Errors::ProxyParseError, "Proxy is invalid"
410
- end
411
411
  @data[:proxy] = {
412
412
  :host => uri.host,
413
+ # path is only sensible for a Unix socket proxy
414
+ :path => uri.scheme == UNIX ? uri.path : nil,
413
415
  :port => uri.port,
414
416
  :scheme => uri.scheme,
415
417
  }
@@ -419,6 +421,16 @@ module Excon
419
421
  if uri.user
420
422
  @data[:proxy][:user] = uri.user
421
423
  end
424
+ if @data[:proxy][:scheme] == UNIX
425
+ if @data[:proxy][:host]
426
+ raise ArgumentError, "The `:host` parameter should not be set for `unix://` proxies.\n" +
427
+ "When supplying a `unix://` URI, it should start with `unix:/` or `unix:///`."
428
+ end
429
+ else
430
+ unless uri.host && uri.port && uri.scheme
431
+ raise Excon::Errors::ProxyParseError, "Proxy is invalid"
432
+ end
433
+ end
422
434
  else
423
435
  raise Excon::Errors::ProxyParseError, "Proxy is invalid"
424
436
  end
@@ -1,6 +1,6 @@
1
1
  module Excon
2
2
 
3
- VERSION = '0.39.6'
3
+ VERSION = '0.40.0'
4
4
 
5
5
  CR_NL = "\r\n"
6
6
 
@@ -81,6 +81,7 @@ module Excon
81
81
  :scheme,
82
82
  :socket,
83
83
  :ssl_ca_file,
84
+ :ssl_ca_path,
84
85
  :ssl_verify_callback,
85
86
  :ssl_verify_peer,
86
87
  :ssl_version,
@@ -46,7 +46,8 @@ module Excon
46
46
  :status => status
47
47
  }
48
48
 
49
- unless datum[:scheme] == UNIX
49
+ unix_proxy = datum[:proxy] ? datum[:proxy][:scheme] == UNIX : false
50
+ unless datum[:scheme] == UNIX || unix_proxy
50
51
  datum[:response].merge!(
51
52
  :remote_ip => socket.remote_ip,
52
53
  :local_port => socket.local_port,
@@ -5,8 +5,10 @@ module Excon
5
5
 
6
6
  def connect
7
7
  @socket = ::Socket.new(::Socket::AF_UNIX, ::Socket::SOCK_STREAM, 0)
8
- sockaddr = ::Socket.sockaddr_un(@data[:socket])
9
-
8
+ # If a Unix proxy was specified, the :path option will be set for it,
9
+ # otherwise fall back to the :socket option.
10
+ proxy_path = @data[:proxy] ? @data[:proxy][:path] : nil
11
+ sockaddr = ::Socket.sockaddr_un(proxy_path || @data[:socket])
10
12
  if @nonblock
11
13
  begin
12
14
  @socket.connect_nonblock(sockaddr)
@@ -12,13 +12,23 @@ Shindo.tests("Excon support for middlewares that return canned responses") do
12
12
  end
13
13
  end
14
14
 
15
- tests('does not mutate the canned response body').returns("canned") do
15
+ tests('does not mutate the canned response body').returns(the_body) do
16
+ Excon.get(
17
+ 'http://some-host.com/some-path',
18
+ :middlewares => [canned_response_middleware] + Excon.defaults[:middlewares]
19
+ ).body
20
+ end
21
+
22
+ tests('yields non-mutated body to response_block').returns(the_body) do
23
+ body = ''
24
+ response_block = lambda { |chunk, _, _| body << chunk }
16
25
  Excon.get(
17
26
  'http://some-host.com/some-path',
18
27
  :middlewares => [canned_response_middleware] + Excon.defaults[:middlewares],
19
- :response_block => Proc.new { } # to force streaming
28
+ :response_block => response_block
20
29
  )
21
- the_body
30
+ body
22
31
  end
32
+
23
33
  end
24
34
 
@@ -35,7 +35,7 @@ Shindo.tests('Excon stubs') do
35
35
  response.status
36
36
  end
37
37
 
38
- tests('request body with response_block given').returns('body') do
38
+ tests('response_block yields body').returns('body') do
39
39
  body = ''
40
40
  response_block = lambda do |chunk, remaining_bytes, total_bytes|
41
41
  body << chunk
@@ -44,6 +44,11 @@ Shindo.tests('Excon stubs') do
44
44
  body
45
45
  end
46
46
 
47
+ tests('response.body empty with response_block').returns('') do
48
+ response_block = lambda { |_, _, _| }
49
+ connection.request(:method => :get, :path => '/content-length/100', :response_block => response_block).body
50
+ end
51
+
47
52
  Excon.stubs.clear
48
53
 
49
54
  end
@@ -99,7 +104,7 @@ Shindo.tests('Excon stubs') do
99
104
  response.status
100
105
  end
101
106
 
102
- tests('request body with response block given').returns('body') do
107
+ tests('response_block yields body').returns('body') do
103
108
  body = ''
104
109
  response_block = lambda do |chunk, remaining_bytes, total_bytes|
105
110
  body << chunk
@@ -108,6 +113,11 @@ Shindo.tests('Excon stubs') do
108
113
  body
109
114
  end
110
115
 
116
+ tests('response.body empty with response_block').returns('') do
117
+ response_block = lambda { |_, _, _| }
118
+ connection.request(:body => 'body', :method => :get, :path => '/content-length/100', :response_block => response_block).body
119
+ end
120
+
111
121
  Excon.stubs.clear
112
122
 
113
123
  end
@@ -146,7 +156,8 @@ Shindo.tests('Excon stubs') do
146
156
  Excon.stubs.clear
147
157
 
148
158
  tests("stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})") do
149
- test("with response_block") do
159
+
160
+ test("response_block yields body") do
150
161
  connection = Excon.new('http://127.0.0.1:9292', :mock => true)
151
162
  Excon.stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})
152
163
 
@@ -157,6 +168,14 @@ Shindo.tests('Excon stubs') do
157
168
  connection.request(:method => :get, :path => '/content-length/100', :response_block => response_block)
158
169
  chunks == ['x' * Excon::DEFAULT_CHUNK_SIZE, 'x']
159
170
  end
171
+
172
+ tests("response.body empty with response_block").returns('') do
173
+ connection = Excon.new('http://127.0.0.1:9292', :mock => true)
174
+ Excon.stub({}, {:body => 'x' * (Excon::DEFAULT_CHUNK_SIZE + 1)})
175
+ response_block = lambda { |_, _, _| }
176
+ connection.request(:method => :get, :path => '/content-length/100', :response_block => response_block).body
177
+ end
178
+
160
179
  end
161
180
 
162
181
  Excon.stubs.clear
@@ -27,6 +27,27 @@ Shindo.tests('Excon proxy support') do
27
27
  end
28
28
  end
29
29
 
30
+ tests('with fully-specified Unix socket proxy: unix:///') do
31
+ connection = nil
32
+
33
+ tests('connection.data[:proxy][:host]').returns(nil) do
34
+ connection = Excon.new('http://foo.com', :proxy => 'unix:///tmp/myproxy.sock')
35
+ connection.data[:proxy][:host]
36
+ end
37
+
38
+ tests('connection.data[:proxy][:port]').returns(nil) do
39
+ connection.data[:proxy][:port]
40
+ end
41
+
42
+ tests('connection.data[:proxy][:scheme]').returns('unix') do
43
+ connection.data[:proxy][:scheme]
44
+ end
45
+
46
+ tests('connection.data[:proxy][:path]').returns('/tmp/myproxy.sock') do
47
+ connection.data[:proxy][:path]
48
+ end
49
+ end
50
+
30
51
  def env_proxy_tests(env)
31
52
  env_init(env)
32
53
 
@@ -138,6 +159,35 @@ Shindo.tests('Excon proxy support') do
138
159
  env_restore
139
160
  end
140
161
 
162
+ tests('with a unix socket proxy config from the environment') do
163
+ env_init({
164
+ 'http_proxy' => 'unix:///tmp/myproxy.sock',
165
+ })
166
+
167
+ tests('an https connection') do
168
+ connection = nil
169
+
170
+ tests('connection.data[:proxy][:host]').returns(nil) do
171
+ connection = Excon.new('https://secret.com')
172
+ connection.data[:proxy][:host]
173
+ end
174
+
175
+ tests('connection.data[:proxy][:port]').returns(nil) do
176
+ connection.data[:proxy][:port]
177
+ end
178
+
179
+ tests('connection.data[:proxy][:scheme]').returns('unix') do
180
+ connection.data[:proxy][:scheme]
181
+ end
182
+
183
+ tests('connection.data[:proxy][:path]').returns('/tmp/myproxy.sock') do
184
+ connection.data[:proxy][:path]
185
+ end
186
+ end
187
+
188
+ env_restore
189
+ end
190
+
141
191
  end
142
192
 
143
193
  with_rackup('proxy.ru') do
@@ -200,5 +250,32 @@ Shindo.tests('Excon proxy support') do
200
250
 
201
251
  end
202
252
 
253
+ with_unicorn('proxy.ru', 'unix:///tmp/myproxy.sock') do
254
+ pending if RUBY_PLATFORM == 'java' # need to find suitable server for jruby
255
+
256
+ tests('http proxying over unix socket: http://foo.com:8080') do
257
+ response = nil
258
+
259
+ tests('response.status').returns(200) do
260
+ connection = Excon.new('http://foo.com:8080', :proxy => 'unix:///tmp/myproxy.sock')
261
+ response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
262
+
263
+ response.status
264
+ end
265
+
266
+ tests('sent Sent-Host header').returns('foo.com:8080') do
267
+ response.headers['Sent-Host']
268
+ end
269
+
270
+ tests('sent Proxy-Connection header').returns('Keep-Alive') do
271
+ response.headers['Sent-Proxy-Connection']
272
+ end
273
+
274
+ tests('response.body (proxied content)').returns('proxied content') do
275
+ response.body
276
+ end
277
+ end
278
+ end
279
+
203
280
  env_restore
204
281
  end
@@ -20,6 +20,11 @@ Shindo.tests('Excon Response Parsing') do
20
20
  end
21
21
  end
22
22
 
23
+ tests('simple response has empty body').returns('') do
24
+ response_block = lambda { |_, _, _| }
25
+ Excon.get('http://127.0.0.1:9292/chunked/simple', :response_block => response_block).body
26
+ end
27
+
23
28
  tests('with expected response status').
24
29
  returns([['hello ', nil, nil], ['world', nil, nil]]) do
25
30
  capture_response_block do |block|
@@ -69,6 +74,11 @@ Shindo.tests('Excon Response Parsing') do
69
74
  end
70
75
  end
71
76
 
77
+ tests('simple response has empty body').returns('') do
78
+ response_block = lambda { |_, _, _| }
79
+ Excon.get('http://127.0.0.1:9292/content-length/simple', :response_block => response_block).body
80
+ end
81
+
72
82
  tests('with expected response status').
73
83
  returns([['hello', 6, 11], [' worl', 1, 11], ['d', 0, 11]]) do
74
84
  capture_response_block do |block|
@@ -111,6 +121,11 @@ Shindo.tests('Excon Response Parsing') do
111
121
  end
112
122
  end
113
123
 
124
+ tests('simple response has empty body').returns('') do
125
+ response_block = lambda { |_, _, _| }
126
+ Excon.get('http://127.0.0.1:9292/unknown/simple', :response_block => response_block).body
127
+ end
128
+
114
129
  tests('with expected response status').
115
130
  returns([['hello', nil, nil], [' worl', nil, nil], ['d', nil, nil]]) do
116
131
  capture_response_block do |block|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.39.6
4
+ version: 0.40.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dpiddy (Dan Peterson)
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-22 00:00:00.000000000 Z
13
+ date: 2014-10-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport