excon 0.7.5 → 0.7.6

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,3 +1,11 @@
1
+ 0.7.6 10/04/11
2
+ ==============
3
+
4
+ * fixes to provide for using openssl-nonblock for 1.8.x
5
+ * correctly pass per-request settings to socket
6
+ * fix for nonblocking stuff when waiting for socket close
7
+ * use 127.0.0.1 instead of localhost in tests (fixes some errors)
8
+
1
9
  0.7.5 10/03/11
2
10
  ==============
3
11
 
@@ -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.7.5'
17
- s.date = '2011-10-03'
16
+ s.version = '0.7.6'
17
+ s.date = '2011-10-04'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -76,7 +76,9 @@ module Excon
76
76
  params[:path].insert(0, '/')
77
77
  end
78
78
 
79
- if params[:mock]
79
+ unless params[:mock]
80
+ socket.params = params
81
+ else
80
82
  for stub, response in Excon.stubs
81
83
  # all specified non-headers params match and no headers were specified or all specified headers match
82
84
  if (stub.keys - [:headers]).all? {|key| stub[key] == params[key] } &&
@@ -1,6 +1,6 @@
1
1
  module Excon
2
2
  unless const_defined?(:VERSION)
3
- VERSION = '0.7.5'
3
+ VERSION = '0.7.6'
4
4
  end
5
5
 
6
6
  unless const_defined?(:CHUNK_SIZE)
@@ -10,4 +10,17 @@ module Excon
10
10
  unless const_defined?(:HTTP_VERBS)
11
11
  HTTP_VERBS = %w{connect delete get head options post put trace}
12
12
  end
13
+
14
+ unless ::IO.const_defined?(:WaitReadable)
15
+ class ::IO
16
+ module WaitReadable; end
17
+ end
18
+ end
19
+
20
+ unless ::IO.const_defined?(:WaitWritable)
21
+ class ::IO
22
+ module WaitWritable; end
23
+ end
24
+ end
25
+
13
26
  end
@@ -3,17 +3,19 @@ module Excon
3
3
 
4
4
  extend Forwardable
5
5
 
6
+ attr_accessor :params
7
+
6
8
  def_delegators(:@socket, :close, :close)
7
9
  def_delegators(:@socket, :readline, :readline)
8
10
 
9
- def initialize(connection_params = {}, proxy = {})
10
- @connection_params, @proxy = connection_params, proxy
11
+ def initialize(params = {}, proxy = {})
12
+ @params, @proxy = params, proxy
11
13
  @read_buffer, @write_buffer = '', ''
12
14
 
13
15
  @sockaddr = if @proxy
14
16
  ::Socket.sockaddr_in(@proxy[:port].to_i, @proxy[:host])
15
17
  else
16
- ::Socket.sockaddr_in(@connection_params[:port].to_i, @connection_params[:host])
18
+ ::Socket.sockaddr_in(@params[:port].to_i, @params[:host])
17
19
  end
18
20
 
19
21
  @socket = ::Socket.new(::Socket::Constants::AF_INET, ::Socket::Constants::SOCK_STREAM, 0)
@@ -28,7 +30,7 @@ module Excon
28
30
  begin
29
31
  @socket.connect_nonblock(@sockaddr)
30
32
  rescue Errno::EINPROGRESS
31
- IO.select(nil, [@socket], nil, @connection_params[:connect_timeout])
33
+ IO.select(nil, [@socket], nil, @params[:connect_timeout])
32
34
  begin
33
35
  @socket.connect_nonblock(@sockaddr)
34
36
  rescue Errno::EISCONN
@@ -36,27 +38,39 @@ module Excon
36
38
  end
37
39
  end
38
40
 
39
- def read(max_length)
41
+ def read(max_length=nil)
40
42
  begin
41
- until @read_buffer.length >= max_length
42
- @read_buffer << @socket.read_nonblock(max_length - @read_buffer.length)
43
+ if max_length
44
+ until @read_buffer.length >= max_length
45
+ @read_buffer << @socket.read_nonblock(max_length - @read_buffer.length)
46
+ end
47
+ else
48
+ while true
49
+ @read_buffer << @socket.read_nonblock(CHUNK_SIZE)
50
+ end
43
51
  end
44
52
  rescue OpenSSL::SSL::SSLError => error
45
53
  if error.message == 'read would block'
46
- if IO.select([@socket], nil, nil, @connection_params[:read_timeout])
54
+ if IO.select([@socket], nil, nil, @params[:read_timeout])
47
55
  retry
48
56
  else
49
57
  raise(Excon::Errors::Timeout.new("read timeout reached"))
50
58
  end
51
59
  end
52
- rescue Errno::EAGAIN, Errno::EWOULDBLOCK
53
- if IO.select([@socket], nil, nil, @connection_params[:read_timeout])
60
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable
61
+ if IO.select([@socket], nil, nil, @params[:read_timeout])
54
62
  retry
55
63
  else
56
64
  raise(Excon::Errors::Timeout.new("read timeout reached"))
57
65
  end
66
+ rescue EOFError
67
+ end
68
+ if max_length
69
+ @read_buffer.slice!(0, max_length)
70
+ else
71
+ # read until EOFError, so return everything
72
+ @read_buffer.slice!(0, @read_buffer.length)
58
73
  end
59
- @read_buffer.slice!(0, max_length)
60
74
  end
61
75
 
62
76
  def write(data)
@@ -68,14 +82,14 @@ module Excon
68
82
  @write_buffer.slice!(0, written)
69
83
  rescue OpenSSL::SSL::SSLError => error
70
84
  if error.message == 'write would block'
71
- if IO.select(nil, [@socket], nil, @connection_params[:write_timeout])
85
+ if IO.select(nil, [@socket], nil, @params[:write_timeout])
72
86
  retry
73
87
  else
74
88
  raise(Excon::Errors::Timeout.new("write timeout reached"))
75
89
  end
76
90
  end
77
- rescue Errno::EAGAIN, Errno::EWOULDBLOCK
78
- if IO.select(nil, [@socket], nil, @connection_params[:write_timeout])
91
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitWritable
92
+ if IO.select(nil, [@socket], nil, @params[:write_timeout])
79
93
  retry
80
94
  else
81
95
  raise(Excon::Errors::Timeout.new("write timeout reached"))
@@ -17,7 +17,7 @@ module Excon
17
17
 
18
18
  end
19
19
 
20
- def initialize(connection_params = {}, proxy = {})
20
+ def initialize(params = {}, proxy = {})
21
21
  super
22
22
 
23
23
  # create ssl context
@@ -40,17 +40,17 @@ module Excon
40
40
  ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
41
  end
42
42
 
43
- if @connection_params.has_key?(:client_cert) && @connection_params.has_key?(:client_key)
44
- ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@connection_params[:client_cert]))
45
- ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@connection_params[:client_key]))
43
+ if @params.has_key?(:client_cert) && @params.has_key?(:client_key)
44
+ ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@params[:client_cert]))
45
+ ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@params[:client_key]))
46
46
  end
47
47
 
48
48
  @socket = OpenSSL::SSL::SSLSocket.new(@socket, ssl_context)
49
49
  @socket.sync_close = true
50
50
 
51
51
  if @proxy
52
- @socket << "CONNECT " << @connection_params[:host] << ":" << @connection_params[:port] << Excon::Connection::HTTP_1_1
53
- @socket << "Host: " << @connection_params[:host] << ":" << @connection_params[:port] << Excon::Connection::CR_NL << Excon::Connection::CR_NL
52
+ @socket << "CONNECT " << @params[:host] << ":" << @params[:port] << Excon::Connection::HTTP_1_1
53
+ @socket << "Host: " << @params[:host] << ":" << @params[:port] << Excon::Connection::CR_NL << Excon::Connection::CR_NL
54
54
 
55
55
  # eat the proxy's connection response
56
56
  while line = @socket.readline.strip
@@ -63,7 +63,7 @@ module Excon
63
63
 
64
64
  # verify connection
65
65
  if Excon.ssl_verify_peer
66
- @socket.post_connection_check(@connection_params[:host])
66
+ @socket.post_connection_check(@params[:host])
67
67
  end
68
68
 
69
69
  @socket
@@ -106,7 +106,7 @@ Shindo.tests('Excon proxy support') do
106
106
  with_rackup('proxy.ru') do
107
107
 
108
108
  tests('http proxying: http://foo.com:8080') do
109
- connection = Excon.new('http://foo.com:8080', :proxy => 'http://localhost:9292')
109
+ connection = Excon.new('http://foo.com:8080', :proxy => 'http://127.0.0.1:9292')
110
110
  response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})
111
111
 
112
112
  tests('response.status').returns(200) 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: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 5
10
- version: 0.7.5
9
+ - 6
10
+ version: 0.7.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - geemus (Wesley Beary)
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-03 00:00:00 Z
18
+ date: 2011-10-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: open4