excon 0.27.6 → 0.28.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.

@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- excon (0.27.6)
4
+ excon (0.28.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,3 +1,15 @@
1
+ 0.28.0 10/28/2013
2
+ =================
3
+
4
+ tag warning messages with [excon]
5
+ allow specific ssl_versions
6
+ fixes around param validation
7
+ create a new connection for redirect_follower middleware
8
+ add connection_uri/request_uri to utils
9
+ avoid mutating connection data
10
+ remove connection key in redirect_follower
11
+
12
+
1
13
  0.27.6 10/15/2013
2
14
  =================
3
15
 
@@ -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.27.6'
17
- s.date = '2013-10-15'
16
+ s.version = '0.28.0'
17
+ s.date = '2013-10-28'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -123,7 +123,7 @@ Gem::Specification.new do |s|
123
123
  tests/middlewares/idempotent_tests.rb
124
124
  tests/middlewares/instrumentation_tests.rb
125
125
  tests/middlewares/mock_tests.rb
126
- tests/middlewares/redirect_follower.rb
126
+ tests/middlewares/redirect_follower_tests.rb
127
127
  tests/proxy_tests.rb
128
128
  tests/query_string_tests.rb
129
129
  tests/rackups/basic.rb
@@ -148,6 +148,7 @@ Gem::Specification.new do |s|
148
148
  tests/test_helper.rb
149
149
  tests/thread_safety_tests.rb
150
150
  tests/timeout_tests.rb
151
+ tests/utils_tests.rb
151
152
  ]
152
153
  # = MANIFEST =
153
154
 
@@ -80,7 +80,7 @@ module Excon
80
80
  def display_warning(warning)
81
81
  # Respect Ruby's $VERBOSE setting, unless EXCON_DEBUG is set
82
82
  if !$VERBOSE.nil? || ENV['EXCON_DEBUG']
83
- $stderr.puts(warning)
83
+ $stderr.puts "[excon][WARNING] #{ warning }"
84
84
  end
85
85
  end
86
86
 
@@ -128,22 +128,7 @@ module Excon
128
128
  request << datum[:path]
129
129
 
130
130
  # add query to path, if there is one
131
- case datum[:query]
132
- when String
133
- request << '?' << datum[:query]
134
- when Hash
135
- request << '?'
136
- datum[:query].each do |key, values|
137
- if values.nil?
138
- request << key.to_s << '&'
139
- else
140
- [values].flatten.each do |value|
141
- request << key.to_s << '=' << CGI.escape(value.to_s) << '&'
142
- end
143
- end
144
- end
145
- request.chop! # remove trailing '&'
146
- end
131
+ request << query_string(datum)
147
132
 
148
133
  # finish first line with "HTTP/1.1\r\n"
149
134
  request << HTTP_1_1
@@ -358,9 +343,9 @@ module Excon
358
343
  def validate_params(validation, params)
359
344
  valid_keys = case validation
360
345
  when :connection
361
- valid_connection_keys(@data, params)
346
+ valid_connection_keys(params)
362
347
  when :request
363
- valid_request_keys(@data, params)
348
+ valid_request_keys(params)
364
349
  end
365
350
  invalid_keys = params.keys - valid_keys
366
351
  unless invalid_keys.empty?
@@ -1,6 +1,6 @@
1
1
  module Excon
2
2
 
3
- VERSION = '0.27.6'
3
+ VERSION = '0.28.0'
4
4
 
5
5
  CR_NL = "\r\n"
6
6
 
@@ -80,6 +80,7 @@ module Excon
80
80
  :socket,
81
81
  :ssl_ca_file,
82
82
  :ssl_verify_peer,
83
+ :ssl_version,
83
84
  :tcp_nodelay,
84
85
  :uri_parser,
85
86
  :user
@@ -14,17 +14,24 @@ module Excon
14
14
  # delete old/redirect response
15
15
  datum.delete(:response)
16
16
 
17
- response = datum[:connection].request(
18
- datum.merge!(
19
- :host => uri.host,
20
- :path => uri.path,
21
- :port => uri.port,
22
- :query => uri.query,
23
- :scheme => uri.scheme,
24
- :user => (URI.decode(uri.user) if uri.user),
25
- :password => (URI.decode(uri.password) if uri.password)
26
- )
17
+ params = datum.dup
18
+ params.delete(:stack)
19
+ params.delete(:connection)
20
+ params[:headers] = datum[:headers].dup
21
+ params[:headers].delete('Authorization')
22
+ params[:headers].delete('Proxy-Connection')
23
+ params[:headers].delete('Proxy-Authorization')
24
+ params.merge!(
25
+ :scheme => uri.scheme,
26
+ :host => uri.host,
27
+ :port => uri.port,
28
+ :path => uri.path,
29
+ :query => uri.query,
30
+ :user => (URI.decode(uri.user) if uri.user),
31
+ :password => (URI.decode(uri.password) if uri.password)
27
32
  )
33
+
34
+ response = Excon::Connection.new(params).request
28
35
  datum.merge!({:response => response.data})
29
36
  else
30
37
  @stack.response_call(datum)
@@ -25,11 +25,6 @@ module Excon
25
25
  @read_buffer = ''
26
26
  @eof = false
27
27
 
28
- @data[:family] ||= ::Socket::Constants::AF_UNSPEC
29
- if @data[:proxy]
30
- @data[:proxy][:family] ||= ::Socket::Constants::AF_UNSPEC
31
- end
32
-
33
28
  connect
34
29
  end
35
30
 
@@ -133,9 +128,11 @@ module Excon
133
128
  exception = nil
134
129
 
135
130
  addrinfo = if @data[:proxy]
136
- ::Socket.getaddrinfo(@data[:proxy][:host], @data[:proxy][:port], @data[:proxy][:family], ::Socket::Constants::SOCK_STREAM)
131
+ family = @data[:proxy][:family] || ::Socket::Constants::AF_UNSPEC
132
+ ::Socket.getaddrinfo(@data[:proxy][:host], @data[:proxy][:port], family, ::Socket::Constants::SOCK_STREAM)
137
133
  else
138
- ::Socket.getaddrinfo(@data[:host], @data[:port], @data[:family], ::Socket::Constants::SOCK_STREAM)
134
+ family = @data[:family] || ::Socket::Constants::AF_UNSPEC
135
+ ::Socket.getaddrinfo(@data[:host], @data[:port], family, ::Socket::Constants::SOCK_STREAM)
139
136
  end
140
137
 
141
138
  addrinfo.each do |_, port, _, ip, a_family, s_type|
@@ -10,7 +10,7 @@ module Excon
10
10
  # create ssl context
11
11
  ssl_context = OpenSSL::SSL::SSLContext.new
12
12
  ssl_context.ciphers = @data[:ciphers]
13
-
13
+ ssl_context.ssl_version = @data[:ssl_version] if @data[:ssl_version]
14
14
  if @data[:ssl_verify_peer]
15
15
  # turn verification on
16
16
  ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
@@ -2,14 +2,29 @@ module Excon
2
2
  module Utils
3
3
  extend self
4
4
 
5
- def valid_connection_keys(datum, params = {})
5
+ def valid_connection_keys(params = {})
6
6
  Excon::VALID_CONNECTION_KEYS
7
7
  end
8
8
 
9
- def valid_request_keys(datum, params = {})
9
+ def valid_request_keys(params = {})
10
10
  Excon::VALID_REQUEST_KEYS
11
11
  end
12
12
 
13
+ def connection_uri(datum = @data)
14
+ unless datum
15
+ raise ArgumentError, '`datum` must be given unless called on a Connection'
16
+ end
17
+ if datum[:scheme] == UNIX
18
+ '' << datum[:scheme] << '://' << datum[:socket]
19
+ else
20
+ '' << datum[:scheme] << '://' << datum[:host] << port_string(datum)
21
+ end
22
+ end
23
+
24
+ def request_uri(datum)
25
+ connection_uri(datum) << datum[:path] << query_string(datum)
26
+ end
27
+
13
28
  def port_string(datum)
14
29
  if datum[:port].nil? || (datum[:omit_default_port] && ((datum[:scheme].casecmp('http') == 0 && datum[:port] == 80) || (datum[:scheme].casecmp('https') == 0 && datum[:port] == 443)))
15
30
  ''
@@ -17,5 +32,26 @@ module Excon
17
32
  ':' << datum[:port].to_s
18
33
  end
19
34
  end
35
+
36
+ def query_string(datum)
37
+ str = ''
38
+ case datum[:query]
39
+ when String
40
+ str << '?' << datum[:query]
41
+ when Hash
42
+ str << '?'
43
+ datum[:query].sort_by {|k,_| k.to_s }.each do |key, values|
44
+ if values.nil?
45
+ str << key.to_s << '&'
46
+ else
47
+ [values].flatten.each do |value|
48
+ str << key.to_s << '=' << CGI.escape(value.to_s) << '&'
49
+ end
50
+ end
51
+ end
52
+ str.chop! # remove trailing '&'
53
+ end
54
+ str
55
+ end
20
56
  end
21
57
  end
@@ -0,0 +1,68 @@
1
+ Shindo.tests('Excon::Utils') do
2
+
3
+ tests('#connection_uri') do
4
+
5
+ expected_uri = 'unix:///tmp/some.sock'
6
+ tests('using UNIX scheme').returns(expected_uri) do
7
+ connection = Excon.new('unix:///some/path', :socket => '/tmp/some.sock')
8
+ Excon::Utils.connection_uri(connection.data)
9
+ end
10
+
11
+ tests('using HTTP scheme') do
12
+
13
+ expected_uri = 'http://foo.com:80'
14
+ tests('with default port').returns(expected_uri) do
15
+ connection = Excon.new('http://foo.com/some/path')
16
+ Excon::Utils.connection_uri(connection.data)
17
+ end
18
+
19
+ expected_uri = 'http://foo.com'
20
+ tests('without default port').returns(expected_uri) do
21
+ connection = Excon.new('http://foo.com/some/path', :omit_default_port => true)
22
+ Excon::Utils.connection_uri(connection.data)
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ tests('#request_uri') do
30
+
31
+ tests('using UNIX scheme') do
32
+
33
+ expected_uri = 'unix:///tmp/some.sock/some/path'
34
+ tests('without query').returns(expected_uri) do
35
+ connection = Excon.new('unix:/', :socket => '/tmp/some.sock')
36
+ params = { :path => '/some/path' }
37
+ Excon::Utils.request_uri(connection.data.merge(params))
38
+ end
39
+
40
+ expected_uri = 'unix:///tmp/some.sock/some/path?bar=that&foo=this'
41
+ tests('with query').returns(expected_uri) do
42
+ connection = Excon.new('unix:/', :socket => '/tmp/some.sock')
43
+ params = { :path => '/some/path', :query => { :foo => 'this', :bar => 'that' } }
44
+ Excon::Utils.request_uri(connection.data.merge(params))
45
+ end
46
+
47
+ end
48
+
49
+ tests('using HTTP scheme') do
50
+
51
+ expected_uri = 'http://foo.com:80/some/path'
52
+ tests('without query').returns(expected_uri) do
53
+ connection = Excon.new('http://foo.com')
54
+ params = { :path => '/some/path' }
55
+ Excon::Utils.request_uri(connection.data.merge(params))
56
+ end
57
+
58
+ expected_uri = 'http://foo.com:80/some/path?bar=that&foo=this'
59
+ tests('with query').returns(expected_uri) do
60
+ connection = Excon.new('http://foo.com')
61
+ params = { :path => '/some/path', :query => { :foo => 'this', :bar => 'that' } }
62
+ Excon::Utils.request_uri(connection.data.merge(params))
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
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.27.6
4
+ version: 0.28.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-10-15 00:00:00.000000000 Z
14
+ date: 2013-10-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -203,7 +203,7 @@ files:
203
203
  - tests/middlewares/idempotent_tests.rb
204
204
  - tests/middlewares/instrumentation_tests.rb
205
205
  - tests/middlewares/mock_tests.rb
206
- - tests/middlewares/redirect_follower.rb
206
+ - tests/middlewares/redirect_follower_tests.rb
207
207
  - tests/proxy_tests.rb
208
208
  - tests/query_string_tests.rb
209
209
  - tests/rackups/basic.rb
@@ -228,6 +228,7 @@ files:
228
228
  - tests/test_helper.rb
229
229
  - tests/thread_safety_tests.rb
230
230
  - tests/timeout_tests.rb
231
+ - tests/utils_tests.rb
231
232
  homepage: https://github.com/geemus/excon
232
233
  licenses:
233
234
  - MIT
@@ -244,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
244
245
  version: '0'
245
246
  segments:
246
247
  - 0
247
- hash: 748587891276058241
248
+ hash: 527099065426297719
248
249
  required_rubygems_version: !ruby/object:Gem::Requirement
249
250
  none: false
250
251
  requirements: