excon 0.13.4 → 0.14.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/README.md CHANGED
@@ -134,14 +134,18 @@ Alternatively you can pass a block instead of `response_attributes` and it will
134
134
  {:body => params[:body], :status => 200}
135
135
  end
136
136
 
137
- In order to clear previously defined stubs you can use:
137
+ In order to clear all previously defined stubs you can use:
138
138
 
139
139
  Excon.stubs.clear
140
140
 
141
+ Or to simply remove the last defined stub you can use:
142
+
143
+ Excon.stubs.shift
144
+
141
145
  For example, if using RSpec for your test suite you can clear stubs after running each example:
142
146
 
143
147
  config.after(:each) do
144
- Excon.stubs.clear
148
+ Excon.stubs.clear
145
149
  end
146
150
 
147
151
  HTTPS/SSL Issues
@@ -193,7 +197,9 @@ If you don't want to add activesupport to your application, simply define a clas
193
197
  end
194
198
  end
195
199
 
196
- The #instrument method will be called for each HTTP request, retry, and error.
200
+ The #instrument method will be called for each HTTP request, response, retry, and error.
201
+
202
+ For debugging purposes you can also use Excon::StandardInstrumentor to output all events to stderr. This can also be specified by setting the `EXCON_STANDARD_INSTRUMENTOR` ENV var.
197
203
 
198
204
  See [the documentation for ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) for more detail on using the subscription interface. See excon's instrumentation_test.rb for more examples of instrumenting excon.
199
205
 
@@ -1,3 +1,12 @@
1
+ 0.14.0 05/31/12
2
+ ===============
3
+
4
+ make stubs LIFO for ease of use/understanding, updated README to explain
5
+ simplify https proxy logic
6
+ add instrumentation for responses
7
+ add StandardInstrumentor (events got to stderr)
8
+ EXCON_STANDARD_INSTRUMENTOR=true sets StandardInstrumentor as default
9
+
1
10
  0.13.3 04/05/12
2
11
  ===============
3
12
 
@@ -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.13.4'
17
- s.date = '2012-04-12'
16
+ s.version = '0.14.0'
17
+ s.date = '2012-05-31'
18
18
  s.rubyforge_project = 'excon'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -97,6 +97,7 @@ Gem::Specification.new do |s|
97
97
  lib/excon/response.rb
98
98
  lib/excon/socket.rb
99
99
  lib/excon/ssl_socket.rb
100
+ lib/excon/standard_instrumentor.rb
100
101
  tests/bad_tests.rb
101
102
  tests/basic_tests.rb
102
103
  tests/data/xs
@@ -14,6 +14,7 @@ require 'excon/errors'
14
14
  require 'excon/response'
15
15
  require 'excon/socket'
16
16
  require 'excon/ssl_socket'
17
+ require 'excon/standard_instrumentor'
17
18
 
18
19
  module Excon
19
20
  class << self
@@ -103,7 +104,7 @@ module Excon
103
104
  else
104
105
  raise(ArgumentError.new("stub requires either response_params OR a block"))
105
106
  end
106
- stubs << stub
107
+ stubs.unshift(stub)
107
108
  stub
108
109
  end
109
110
 
@@ -37,17 +37,19 @@ module Excon
37
37
  @proxy = setup_proxy(params[:proxy])
38
38
  end
39
39
 
40
- if @connection[:scheme] == HTTPS
41
- # use https_proxy if that has been specified
42
- if ENV.has_key?('https_proxy')
43
- @proxy = setup_proxy(ENV['https_proxy'])
44
- end
40
+ # use https_proxy if that has been specified
41
+ if @connection[:scheme] == HTTPS && ENV.has_key?('https_proxy')
42
+ @proxy = setup_proxy(ENV['https_proxy'])
45
43
  end
46
44
 
47
45
  if @proxy
48
46
  @connection[:headers]['Proxy-Connection'] ||= 'Keep-Alive'
49
47
  end
50
48
 
49
+ if ENV.has_key?('EXCON_STANDARD_INSTRUMENTOR')
50
+ @connection[:instrumentor] = Excon::StandardInstrumentor
51
+ end
52
+
51
53
  # Use Basic Auth if url contains a login
52
54
  if uri.user || uri.password
53
55
  auth = ["#{uri.user}:#{uri.password}"].pack('m').delete("\r\n")
@@ -90,9 +92,11 @@ module Excon
90
92
  else
91
93
  event_name = "#{params[:instrumentor_name]}.request"
92
94
  end
93
- params[:instrumentor].instrument(event_name, params) do
95
+ response = params[:instrumentor].instrument(event_name, params) do
94
96
  request_kernel(params)
95
97
  end
98
+ params[:instrumentor].instrument("#{params[:instrumentor_name]}.response", response.attributes)
99
+ response
96
100
  else
97
101
  request_kernel(params)
98
102
  end
@@ -1,6 +1,6 @@
1
1
  module Excon
2
2
  unless const_defined?(:VERSION)
3
- VERSION = '0.13.4'
3
+ VERSION = '0.14.0'
4
4
  end
5
5
 
6
6
  unless const_defined?(:CHUNK_SIZE)
@@ -0,0 +1,10 @@
1
+ module Excon
2
+ class StandardInstrumentor
3
+ def self.instrument(name, params = {}, &block)
4
+ $stderr.puts("#{name} #{params}")
5
+ if block_given?
6
+ yield
7
+ end
8
+ end
9
+ end
10
+ end
@@ -17,6 +17,7 @@ Shindo.tests('Excon instrumentation') do
17
17
  after do
18
18
  ActiveSupport::Notifications.unsubscribe("excon")
19
19
  ActiveSupport::Notifications.unsubscribe("excon.request")
20
+ ActiveSupport::Notifications.unsubscribe("excon.response")
20
21
  ActiveSupport::Notifications.unsubscribe("excon.retry")
21
22
  ActiveSupport::Notifications.unsubscribe("excon.error")
22
23
  ActiveSupport::Notifications.unsubscribe("gug")
@@ -69,11 +70,11 @@ Shindo.tests('Excon instrumentation') do
69
70
  }
70
71
  end
71
72
 
72
- tests('basic notification').returns('excon.request') do
73
+ tests('basic notification').returns(['excon.request', 'excon.response']) do
73
74
  subscribe(/excon/)
74
75
  stub_success
75
76
  make_request
76
- @events.first.name
77
+ @events.map(&:name)
77
78
  end
78
79
 
79
80
  tests('captures scheme, host, port, and path').returns([:host, :path, :port, :scheme]) do
@@ -83,7 +84,7 @@ Shindo.tests('Excon instrumentation') do
83
84
  [:host, :path, :port, :scheme].select {|k| @events.first.payload.has_key? k}
84
85
  end
85
86
 
86
- tests('params in request overwrite those in construcor').returns('cheezburger') do
87
+ tests('params in request overwrite those in constructor').returns('cheezburger') do
87
88
  subscribe(/excon/)
88
89
  stub_success
89
90
  make_request(false, :host => 'cheezburger')
@@ -135,6 +136,28 @@ Shindo.tests('Excon instrumentation') do
135
136
  (@events.first.duration/1000 - REQUEST_DELAY_SECONDS).abs < 1
136
137
  end
137
138
 
139
+ tests('standard instrumentor').returns(
140
+ ['excon.request', 'excon.retry', 'excon.retry', 'excon.retry', 'excon.error']) do
141
+
142
+ begin
143
+ original_stderr = $stderr
144
+ $stderr = captured_stderr = StringIO.new
145
+ stub_failure
146
+ connection = Excon.new(
147
+ 'http://127.0.0.1:9292',
148
+ :instrumentor => Excon::StandardInstrumentor,
149
+ :mock => true
150
+ )
151
+ raises(Excon::Errors::SocketError) do
152
+ connection.get(:idempotent => true)
153
+ end
154
+
155
+ captured_stderr.string.split("\n").map {|event| event.split(' ').first}
156
+ ensure
157
+ $stderr = original_stderr
158
+ end
159
+ end
160
+
138
161
  tests('use our own instrumentor').returns(
139
162
  ['excon.request', 'excon.retry', 'excon.retry', 'excon.retry', 'excon.error']) do
140
163
  stub_failure
@@ -191,10 +214,10 @@ Shindo.tests('Excon instrumentation') do
191
214
  end
192
215
 
193
216
  with_rackup('basic.ru') do
194
- tests('works unmocked').returns('excon.request') do
217
+ tests('works unmocked').returns(['excon.request', 'excon.response']) do
195
218
  subscribe(/excon/)
196
219
  make_request(false, :mock => false)
197
- @events.first.name
220
+ @events.map(&:name)
198
221
  end
199
222
  end
200
223
  end
@@ -3,6 +3,8 @@ require 'bundler'
3
3
 
4
4
  Bundler.require(:default, :development)
5
5
 
6
+ require 'stringio'
7
+
6
8
  def basic_tests(url = 'http://127.0.0.1:9292')
7
9
 
8
10
  connection = Excon.new(url, :ssl_verify_peer => false)
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.13.4
4
+ version: 0.14.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-04-12 00:00:00.000000000 Z
14
+ date: 2012-05-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70221725989500 !ruby/object:Gem::Requirement
18
+ requirement: &70191342427280 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *70221725989500
26
+ version_requirements: *70191342427280
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: delorean
29
- requirement: &70221725988940 !ruby/object:Gem::Requirement
29
+ requirement: &70191342426160 !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: *70221725988940
37
+ version_requirements: *70191342426160
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: open4
40
- requirement: &70221725988260 !ruby/object:Gem::Requirement
40
+ requirement: &70191342425140 !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: *70221725988260
48
+ version_requirements: *70191342425140
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
- requirement: &70221725987340 !ruby/object:Gem::Requirement
51
+ requirement: &70191342424280 !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: *70221725987340
59
+ version_requirements: *70191342424280
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rdoc
62
- requirement: &70221725985040 !ruby/object:Gem::Requirement
62
+ requirement: &70191342423500 !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: *70221725985040
70
+ version_requirements: *70191342423500
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: shindo
73
- requirement: &70221726000800 !ruby/object:Gem::Requirement
73
+ requirement: &70191342422860 !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: *70221726000800
81
+ version_requirements: *70191342422860
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: sinatra
84
- requirement: &70221726000100 !ruby/object:Gem::Requirement
84
+ requirement: &70191342422180 !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: *70221726000100
92
+ version_requirements: *70191342422180
93
93
  description: EXtended http(s) CONnections
94
94
  email: geemus@gmail.com
95
95
  executables: []
@@ -128,6 +128,7 @@ files:
128
128
  - lib/excon/response.rb
129
129
  - lib/excon/socket.rb
130
130
  - lib/excon/ssl_socket.rb
131
+ - lib/excon/standard_instrumentor.rb
131
132
  - tests/bad_tests.rb
132
133
  - tests/basic_tests.rb
133
134
  - tests/data/xs
@@ -163,6 +164,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
164
  - - ! '>='
164
165
  - !ruby/object:Gem::Version
165
166
  version: '0'
167
+ segments:
168
+ - 0
169
+ hash: 830619460380179228
166
170
  required_rubygems_version: !ruby/object:Gem::Requirement
167
171
  none: false
168
172
  requirements: