excon 0.3.8 → 0.4.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.

@@ -6,7 +6,7 @@ Http(s) EXtended CONnections
6
6
 
7
7
  sudo gem install excon
8
8
 
9
- Now you are ready to get started, easiest is to use one off requests to start. Windows users see the addendum at the end.
9
+ Now you are ready to get started, easiest is to use one off requests to start.
10
10
 
11
11
  require 'rubygems'
12
12
  require 'excon'
@@ -33,15 +33,19 @@ If you need to do something special with a response you can also pass a block th
33
33
 
34
34
  From there you should be able to make just about any request you might need.
35
35
 
36
- == Windows
36
+ == HTTPS/SSL Issues
37
37
 
38
- On windows the default ssl peer certificate verification won't work out for you. You can opt after requiring excon like this:
38
+ On some systems the default ssl peer certificate verification won't work. You can either set a different path to certificates:
39
39
 
40
40
  require 'rubygems'
41
41
  require 'excon'
42
- Excon.ssl_verify_peer = false
42
+ Excon.ssl_ca_path = '/path/to/certs'
43
+
44
+ or, simply turn peer verification off (less secure):
43
45
 
44
- I'll provide a better solution when I can (and you should know that in the mean time this is succeptible to man in the middle attacks).
46
+ require 'rubygems'
47
+ require 'excon'
48
+ Excon.ssl_verify_peer = false
45
49
 
46
50
  == Copyright
47
51
 
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'tach'
3
+
4
+ class Concatenator
5
+ def initialize(string)
6
+ @string = string
7
+ end
8
+
9
+ def call(data)
10
+ @string << data
11
+ end
12
+ end
13
+
14
+ string = "0123456789ABCDEF"
15
+
16
+ Tach.meter(100_000) do
17
+ tach('class') do
18
+ s = ""
19
+ obj = Concatenator.new(s)
20
+ 10.times { obj.call(string) }
21
+ end
22
+
23
+ tach('lambda') do
24
+ s = ""
25
+ obj = lambda {|data| s << data }
26
+ 10.times { obj.call(string) }
27
+ end
28
+ end
29
+
30
+ # ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
31
+ #
32
+ # +--------+----------+
33
+ # | tach | total |
34
+ # +--------+----------+
35
+ # | class | 1.450284 |
36
+ # +--------+----------+
37
+ # | lambda | 2.506496 |
38
+ # +--------+----------+
39
+
40
+ # ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux]
41
+ #
42
+ # +--------+----------+
43
+ # | tach | total |
44
+ # +--------+----------+
45
+ # | class | 1.373917 |
46
+ # +--------+----------+
47
+ # | lambda | 2.589384 |
48
+ # +--------+----------+
49
+
50
+
@@ -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.3.8'
17
- s.date = '2011-01-07'
16
+ s.version = '0.4.0'
17
+ s.date = '2011-01-12'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -65,6 +65,7 @@ Gem::Specification.new do |s|
65
65
  Gemfile
66
66
  README.rdoc
67
67
  Rakefile
68
+ benchmarks/class_vs_lambda.rb
68
69
  benchmarks/concat_vs_insert.rb
69
70
  benchmarks/concat_vs_interpolate.rb
70
71
  benchmarks/cr_lf.rb
@@ -3,6 +3,7 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  require 'cgi'
5
5
  require 'openssl'
6
+ require 'rbconfig'
6
7
  require 'socket'
7
8
  require 'uri'
8
9
 
@@ -13,15 +14,30 @@ require 'excon/response'
13
14
  module Excon
14
15
 
15
16
  unless const_defined?(:VERSION)
16
- VERSION = '0.3.8'
17
+ VERSION = '0.4.0'
17
18
  end
18
19
 
19
20
  unless const_defined?(:CHUNK_SIZE)
20
21
  CHUNK_SIZE = 1048576 # 1 megabyte
21
22
  end
22
23
 
24
+ def self.ssl_ca_path
25
+ @ssl_ca_path
26
+ end
27
+
28
+ def self.ssl_ca_path=(new_ssl_ca_path)
29
+ @ssl_ca_path = new_ssl_ca_path
30
+ end
31
+
32
+ # setup ssl defaults based on platform
33
+ case Config::CONFIG['host_os']
34
+ when /mswin|win32|dos|cygwin|mingw/i
35
+ @ssl_verify_peer = false
36
+ else
37
+ @ssl_verify_peer = true
38
+ end
39
+
23
40
  # Status of ssl peer verification
24
- @ssl_verify_peer = true
25
41
  def self.ssl_verify_peer
26
42
  @ssl_verify_peer
27
43
  end
@@ -26,7 +26,7 @@ module Excon
26
26
  :query => uri.query,
27
27
  :scheme => uri.scheme
28
28
  }.merge!(params)
29
- @socket_key = "#{@connection[:host]}:#{@connection[:port]}"
29
+ @socket_key = '' << @connection[:host] << ':' << @connection[:port].to_s
30
30
  reset
31
31
  end
32
32
 
@@ -64,13 +64,13 @@ module Excon
64
64
  for key, values in params[:query]
65
65
  case values
66
66
  when nil
67
- request << "#{key}&"
67
+ request << key.to_s << '&'
68
68
  when Array
69
69
  for value in values
70
- request << "#{key}=#{CGI.escape(value.to_s)}&"
70
+ request << key.to_s << '=' << CGI.escape(value.to_s) << '&'
71
71
  end
72
72
  else
73
- request << "#{key}=#{CGI.escape(values.to_s)}&"
73
+ request << key.to_s << '=' << CGI.escape(values.to_s) << '&'
74
74
  end
75
75
  end
76
76
  request.chop! # remove trailing '&'
@@ -168,10 +168,14 @@ module Excon
168
168
  # turn verification on
169
169
  ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
170
170
 
171
- # use default cert store
172
- store = OpenSSL::X509::Store.new
173
- store.set_default_paths
174
- ssl_context.cert_store = store
171
+ if Excon.ssl_ca_path
172
+ ssl_context.ca_path = Excon.ssl_ca_path
173
+ else
174
+ # use default cert store
175
+ store = OpenSSL::X509::Store.new
176
+ store.set_default_paths
177
+ ssl_context.cert_store = store
178
+ end
175
179
  else
176
180
  # turn verification off
177
181
  ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -23,7 +23,7 @@ module Excon
23
23
  unless params[:method].to_s.upcase == 'HEAD'
24
24
  if !block || (params[:expects] && ![*params[:expects]].include?(response.status))
25
25
  response.body = ''
26
- block = lambda { |chunk| response.body << chunk }
26
+ block = Concatenator.new(response.body)
27
27
  end
28
28
 
29
29
  if response.headers['Transfer-Encoding'] && response.headers['Transfer-Encoding'].downcase == 'chunked'
@@ -59,4 +59,14 @@ module Excon
59
59
  end
60
60
 
61
61
  end
62
+
63
+ class Concatenator
64
+ def initialize(string)
65
+ @string = string
66
+ end
67
+
68
+ def call(data)
69
+ @string << data
70
+ end
71
+ end
62
72
  end
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: 3
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 8
10
- version: 0.3.8
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
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-01-07 00:00:00 -08:00
18
+ date: 2011-01-12 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -74,6 +74,7 @@ files:
74
74
  - Gemfile
75
75
  - README.rdoc
76
76
  - Rakefile
77
+ - benchmarks/class_vs_lambda.rb
77
78
  - benchmarks/concat_vs_insert.rb
78
79
  - benchmarks/concat_vs_interpolate.rb
79
80
  - benchmarks/cr_lf.rb