rack-mini-profiler 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack-mini-profiler might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -38,3 +38,9 @@
38
38
  * Version 0.1.8
39
39
  * Unicode fix
40
40
  * Version 0.1.9
41
+
42
+ 7-August-2012 - Sam
43
+
44
+ * Added option to disable profiler for the current session (pp=disable / pp=enable)
45
+ * yajl compatability contributed by Sven Riedel
46
+
data/README.md CHANGED
File without changes
@@ -63,11 +63,26 @@ module Rack
63
63
 
64
64
  # remove the mini profiler cookie, only used when config.authorization_mode == :whitelist
65
65
  def remove_profiling_cookie(headers)
66
- Rack::Utils.delete_cookie_header!(headers, '__profilin')
66
+ Rack::Utils.set_cookie_header!(headers, '__profilin', :value => 'notstylin', :path => '/')
67
67
  end
68
68
 
69
69
  def set_profiling_cookie(headers)
70
- Rack::Utils.set_cookie_header!(headers, '__profilin', 'stylin')
70
+ Rack::Utils.set_cookie_header!(headers, '__profilin', :value => 'stylin', :path => '/')
71
+ end
72
+
73
+ # user has the mini profiler cookie, only used when config.authorization_mode == :whitelist
74
+ def has_disable_profiling_cookie?(env)
75
+ env['HTTP_COOKIE'] && env['HTTP_COOKIE'].include?("__profilin_disable=stylin")
76
+ end
77
+
78
+ # remove the mini profiler cookie, only used when config.authorization_mode == :whitelist
79
+ def remove_disable_profiling_cookie(headers)
80
+ #something is odd with delete_cookie_header
81
+ Rack::Utils.set_cookie_header!(headers, '__profilin_disable', :value => 'notstylin', :path => '/')
82
+ end
83
+
84
+ def set_disable_profiling_cookie(headers)
85
+ Rack::Utils.set_cookie_header!(headers, '__profilin_disable', :value => 'stylin', :path => '/')
71
86
  end
72
87
 
73
88
  def create_current(env={}, options={})
@@ -181,11 +196,12 @@ module Rack
181
196
 
182
197
  def call(env)
183
198
  status = headers = body = nil
199
+ query_string = env['QUERY_STRING']
184
200
  path = env['PATH_INFO']
185
201
 
186
202
  skip_it = (@config.pre_authorize_cb && !@config.pre_authorize_cb.call(env)) ||
187
203
  (@config.skip_paths && @config.skip_paths.any?{ |p| path[0,p.length] == p}) ||
188
- env["QUERY_STRING"] =~ /pp=skip/
204
+ query_string =~ /pp=skip/
189
205
 
190
206
  has_profiling_cookie = MiniProfiler.has_profiling_cookie?(env)
191
207
 
@@ -198,13 +214,29 @@ module Rack
198
214
  end
199
215
 
200
216
  # handle all /mini-profiler requests here
201
- return serve_html(env) if env['PATH_INFO'].start_with? @config.base_url_path
217
+ return serve_html(env) if path.start_with? @config.base_url_path
218
+
219
+ has_disable_cookie = MiniProfiler.has_disable_profiling_cookie?(env)
220
+ # manual session disable / enable
221
+ if query_string =~ /pp=disable/ || has_disable_cookie
222
+ skip_it = true
223
+ end
224
+
225
+ if query_string =~ /pp=enable/
226
+ skip_it = false
227
+ end
228
+
229
+ if skip_it
230
+ status,headers,body = @app.call(env)
231
+ MiniProfiler.set_disable_profiling_cookie(headers) unless has_disable_cookie
232
+ return [status,headers,body]
233
+ end
202
234
 
203
235
  MiniProfiler.create_current(env, @config)
204
236
  MiniProfiler.deauthorize_request if @config.authorization_mode == :whitelist
205
- if env["QUERY_STRING"] =~ /pp=no-backtrace/
237
+ if query_string =~ /pp=no-backtrace/
206
238
  current.skip_backtrace = true
207
- elsif env["QUERY_STRING"] =~ /pp=full-backtrace/
239
+ elsif query_string =~ /pp=full-backtrace/
208
240
  current.full_backtrace = true
209
241
  end
210
242
 
@@ -212,7 +244,7 @@ module Rack
212
244
  quit_sampler = false
213
245
  backtraces = nil
214
246
  missing_stacktrace = false
215
- if env["QUERY_STRING"] =~ /pp=sample/
247
+ if query_string =~ /pp=sample/
216
248
  backtraces = []
217
249
  t = Thread.current
218
250
  Thread.new {
@@ -240,6 +272,9 @@ module Rack
240
272
  start = Time.now
241
273
  begin
242
274
  status,headers,body = @app.call(env)
275
+ if has_disable_cookie
276
+ MiniProfiler.remove_disable_profiling_cookie(headers)
277
+ end
243
278
  ensure
244
279
  if backtraces
245
280
  done_sampling = true
@@ -256,12 +291,12 @@ module Rack
256
291
  return [status,headers,body] if skip_it
257
292
 
258
293
  # we must do this here, otherwise current[:discard] is not being properly treated
259
- if env["QUERY_STRING"] =~ /pp=env/
294
+ if query_string =~ /pp=env/
260
295
  body.close if body.respond_to? :close
261
296
  return dump_env env
262
297
  end
263
298
 
264
- if env["QUERY_STRING"] =~ /pp=help/
299
+ if query_string =~ /pp=help/
265
300
  body.close if body.respond_to? :close
266
301
  return help
267
302
  end
@@ -348,6 +383,8 @@ module Rack
348
383
  pp=no-backtrace : don't collect stack traces from all the SQL executed
349
384
  pp=full-backtrace : enable full backtrace for SQL executed
350
385
  pp=sample : sample stack traces and return a report isolating heavy usage (requires the stacktrace gem)
386
+ pp=disable : disable profiling for this session
387
+ pp=enable : enable profiling for this session (if previously disabled)
351
388
  "
352
389
  if (category == :stacktrace)
353
390
  body = "pp=stacktrace requires the stacktrace gem - add gem 'stacktrace' to your Gemfile"
@@ -22,7 +22,12 @@ module Rack
22
22
  end
23
23
 
24
24
  def to_json(*a)
25
- ::JSON.generate(@attributes, a[0])
25
+ if a[0] == nil
26
+ # YAJL doesnt like nil as options
27
+ ::JSON.generate( @attributes )
28
+ else
29
+ ::JSON.generate(@attributes, a[0])
30
+ end
26
31
  end
27
32
 
28
33
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rack-mini-profiler"
3
- s.version = "0.1.9"
3
+ s.version = "0.1.10"
4
4
  s.summary = "Profiles loading speed for rack applications."
5
5
  s.authors = ["Aleks Totic","Sam Saffron", "Robin Ward"]
6
6
  s.description = "Page loading speed displayed on every page. Optimize while you develop, performance is a feature."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mini-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
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: 2012-07-30 00:00:00.000000000 Z
14
+ date: 2012-08-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rack
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  segments:
132
132
  - 0
133
- hash: 663723709
133
+ hash: -296105007
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  none: false
136
136
  requirements:
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  segments:
141
141
  - 0
142
- hash: 663723709
142
+ hash: -296105007
143
143
  requirements: []
144
144
  rubyforge_project:
145
145
  rubygems_version: 1.8.24