excon 0.9.6 → 0.10.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.

data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'jruby-openssl', :platform => :jruby
5
+ gem 'jruby-openssl', '< 0.7.4', :platform => :jruby
6
6
 
7
7
  group :benchmark do
8
8
  gem 'em-http-request'
data/Rakefile CHANGED
@@ -48,14 +48,6 @@ Shindo::Rake.new
48
48
 
49
49
  task :default => :tests
50
50
 
51
- desc "Generate RCov test coverage and open in your browser"
52
- task :coverage do
53
- require 'rcov'
54
- sh "rm -fr coverage"
55
- sh "rcov tests/test_*.rb"
56
- sh "open coverage/index.html"
57
- end
58
-
59
51
  require 'rdoc/task'
60
52
  Rake::RDocTask.new do |rdoc|
61
53
  rdoc.rdoc_dir = 'rdoc'
@@ -1,3 +1,11 @@
1
+ 0.10.0 03/01/12
2
+ ===============
3
+
4
+ * avoid setting/passing Content-Length headers for GET requests with no body
5
+ * remove rcov from tasks/bundle in development
6
+ * automatically parse and use basic auth when passed as part of a uri
7
+ * fix for erroneous recursion in Excon.defaults=
8
+
1
9
  0.9.6 02/22/12
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.9.6'
17
- s.date = '2012-02-22'
16
+ s.version = '0.10.0'
17
+ s.date = '2012-03-01'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -104,6 +104,7 @@ Gem::Specification.new do |s|
104
104
  tests/proxy_tests.rb
105
105
  tests/query_string_tests.rb
106
106
  tests/rackups/basic.ru
107
+ tests/rackups/basic_auth.ru
107
108
  tests/rackups/proxy.ru
108
109
  tests/rackups/query_string.ru
109
110
  tests/rackups/request_methods.ru
@@ -35,7 +35,7 @@ module Excon
35
35
  # Change defaults for Excon connections
36
36
  # @return [Hash] defaults for Excon connections
37
37
  def defaults=(new_defaults)
38
- self.defaults = new_defaults
38
+ @defaults = new_defaults
39
39
  end
40
40
 
41
41
  # Status of mocking
@@ -48,6 +48,12 @@ module Excon
48
48
  @connection[:headers]['Proxy-Connection'] ||= 'Keep-Alive'
49
49
  end
50
50
 
51
+ # Use Basic Auth if url contains a login
52
+ if uri.user || uri.password
53
+ auth = ["#{uri.user}:#{uri.password}"].pack('m').delete("\r\n")
54
+ @connection[:headers]['Authorization'] ||= "Basic #{auth}"
55
+ end
56
+
51
57
  @socket_key = '' << @connection[:host] << ':' << @connection[:port]
52
58
  reset
53
59
  end
@@ -170,17 +176,21 @@ module Excon
170
176
 
171
177
  # calculate content length and set to handle non-ascii
172
178
  unless params[:headers].has_key?('Content-Length')
173
- params[:headers]['Content-Length'] = case params[:body]
174
- when File
175
- params[:body].binmode
176
- File.size(params[:body])
177
- when String
178
- if FORCE_ENC
179
- params[:body].force_encoding('BINARY')
179
+ # The HTTP spec isn't clear on it, but specifically, GET requests don't usually send bodies;
180
+ # if they don't, sending Content-Length:0 can cause issues.
181
+ unless (params[:method].to_s.casecmp('GET') == 0 && params[:body].nil?)
182
+ params[:headers]['Content-Length'] = case params[:body]
183
+ when File
184
+ params[:body].binmode
185
+ File.size(params[:body])
186
+ when String
187
+ if FORCE_ENC
188
+ params[:body].force_encoding('BINARY')
189
+ end
190
+ params[:body].length
191
+ else
192
+ 0
180
193
  end
181
- params[:body].length
182
- else
183
- 0
184
194
  end
185
195
  end
186
196
 
@@ -198,7 +208,7 @@ module Excon
198
208
  socket.write(request)
199
209
 
200
210
  # write out the body
201
- if params[:headers]['Content-Length'] != 0
211
+ unless params[:body].nil? || params[:body].empty?
202
212
  if params[:body].is_a?(String)
203
213
  socket.write(params[:body])
204
214
  else
@@ -1,6 +1,6 @@
1
1
  module Excon
2
2
  unless const_defined?(:VERSION)
3
- VERSION = '0.9.6'
3
+ VERSION = '0.10.0'
4
4
  end
5
5
 
6
6
  unless const_defined?(:CHUNK_SIZE)
@@ -42,7 +42,7 @@ module Excon
42
42
  if transfer_encoding_chunked
43
43
  # 2 == "/r/n".length
44
44
  while (chunk_size = socket.readline.chop!.to_i(16)) > 0
45
- yield(socket.read(chunk_size + 2).chop!, nil, content_length)
45
+ yield(socket.read(chunk_size + 2).chop!, nil, nil)
46
46
  end
47
47
  socket.read(2)
48
48
  elsif remaining = content_length
@@ -4,8 +4,31 @@ with_rackup('basic.ru') do
4
4
  end
5
5
  end
6
6
 
7
+ with_rackup('basic_auth.ru') do
8
+ Shindo.tests('Excon basics (Basic Auth Pass)') do
9
+ basic_tests('http://test_user:test_password@127.0.0.1:9292')
10
+ end
11
+
12
+ Shindo.tests('Excon basics (Basic Auth Fail)') do
13
+ cases = [
14
+ ['correct user, no password', 'http://test_user@127.0.0.1:9292'],
15
+ ['correct user, wrong password', 'http://test_user:fake_password@127.0.0.1:9292'],
16
+ ['wrong user, correct password', 'http://fake_user:test_password@127.0.0.1:9292'],
17
+ ]
18
+ cases.each do |desc,url|
19
+ connection = Excon.new(url)
20
+ response = connection.request(:method => :get, :path => '/content-length/100')
21
+
22
+ tests("response.status for #{desc}").returns(401) do
23
+ response.status
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
7
30
  with_rackup('ssl.ru') do
8
31
  Shindo.tests('Excon basics (ssl)') do
9
32
  basic_tests('https://127.0.0.1:9443')
10
33
  end
11
- end
34
+ end
@@ -0,0 +1,23 @@
1
+ require 'sinatra'
2
+
3
+ class App < Sinatra::Base
4
+ before do
5
+ auth ||= Rack::Auth::Basic::Request.new(request.env)
6
+ user, pass = auth.provided? && auth.basic? && auth.credentials
7
+ unless [user, pass] == ["test_user", "test_password"]
8
+ response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
9
+ throw(:halt, [401, "Not authorized\n"])
10
+ end
11
+ end
12
+
13
+ get('/content-length/:value') do |value|
14
+ headers("Custom" => "Foo: bar")
15
+ 'x' * value.to_i
16
+ end
17
+
18
+ post('/body-sink') do
19
+ request.body.read.size.to_s
20
+ end
21
+ end
22
+
23
+ run App
@@ -12,6 +12,10 @@ Shindo.tests('Excon request methods') do
12
12
  Excon.post('http://localhost:9292').body
13
13
  end
14
14
 
15
+ tests('Excon.delete').returns('DELETE') do
16
+ Excon.delete('http://localhost:9292').body
17
+ end
18
+
15
19
  end
16
20
 
17
21
  tests 'with a connection object' do
@@ -26,6 +30,10 @@ Shindo.tests('Excon request methods') do
26
30
  connection.post.body
27
31
  end
28
32
 
33
+ tests('connection.delete').returns('DELETE') do
34
+ connection.delete.body
35
+ end
36
+
29
37
  end
30
38
 
31
39
  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.9.6
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-02-22 00:00:00.000000000Z
14
+ date: 2012-03-01 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &9166800 !ruby/object:Gem::Requirement
18
+ requirement: &70310527674080 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 3.1.3
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *9166800
26
+ version_requirements: *70310527674080
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: delorean
29
- requirement: &9166610 !ruby/object:Gem::Requirement
29
+ requirement: &70310527672680 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *9166610
37
+ version_requirements: *70310527672680
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: open4
40
- requirement: &9166380 !ruby/object:Gem::Requirement
40
+ requirement: &70310527671680 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *9166380
48
+ version_requirements: *70310527671680
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
- requirement: &9166170 !ruby/object:Gem::Requirement
51
+ requirement: &70310527670180 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *9166170
59
+ version_requirements: *70310527670180
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rdoc
62
- requirement: &9165960 !ruby/object:Gem::Requirement
62
+ requirement: &70310527668720 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *9165960
70
+ version_requirements: *70310527668720
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: shindo
73
- requirement: &9165750 !ruby/object:Gem::Requirement
73
+ requirement: &70310527667260 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *9165750
81
+ version_requirements: *70310527667260
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: sinatra
84
- requirement: &9165510 !ruby/object:Gem::Requirement
84
+ requirement: &70310527665960 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *9165510
92
+ version_requirements: *70310527665960
93
93
  description: EXtended http(s) CONnections
94
94
  email: geemus@gmail.com
95
95
  executables: []
@@ -135,6 +135,7 @@ files:
135
135
  - tests/proxy_tests.rb
136
136
  - tests/query_string_tests.rb
137
137
  - tests/rackups/basic.ru
138
+ - tests/rackups/basic_auth.ru
138
139
  - tests/rackups/proxy.ru
139
140
  - tests/rackups/query_string.ru
140
141
  - tests/rackups/request_methods.ru
@@ -161,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
162
  version: '0'
162
163
  segments:
163
164
  - 0
164
- hash: -511600863
165
+ hash: 3014596879037877365
165
166
  required_rubygems_version: !ruby/object:Gem::Requirement
166
167
  none: false
167
168
  requirements:
@@ -170,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
171
  version: '0'
171
172
  requirements: []
172
173
  rubyforge_project: excon
173
- rubygems_version: 1.8.6
174
+ rubygems_version: 1.8.10
174
175
  signing_key:
175
176
  specification_version: 2
176
177
  summary: speed, persistence, http(s)