rack-webprofiler 0.1.0.pre.beta1 → 0.1.0.pre.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +7 -17
  3. data/lib/rack/templates/assets/css/profiler.css +1 -1
  4. data/lib/rack/templates/assets/css/rwpt.css +1 -1
  5. data/lib/rack/templates/assets/sass/_highlight.scss +63 -0
  6. data/lib/rack/templates/assets/sass/_variables.scss +1 -0
  7. data/lib/rack/templates/assets/sass/profiler.scss +1 -1
  8. data/lib/rack/templates/assets/sass/rwpt.scss +27 -9
  9. data/lib/rack/templates/async.erb +8 -8
  10. data/lib/rack/templates/panel/_sidebar.erb +3 -23
  11. data/lib/rack/templates/panel/index.erb +18 -6
  12. data/lib/rack/templates/panel/layout.erb +9 -5
  13. data/lib/rack/templates/panel/show.erb +25 -7
  14. data/lib/rack/templates/profiler.erb +15 -12
  15. data/lib/rack/web_profiler/collector/rack/request_collector.rb +38 -35
  16. data/lib/rack/web_profiler/collector/ruby_collector.rb +9 -7
  17. data/lib/rack/web_profiler/collector/time_collector.rb +2 -2
  18. data/lib/rack/web_profiler/collector/view.rb +44 -0
  19. data/lib/rack/web_profiler/collector.rb +29 -16
  20. data/lib/rack/web_profiler/config.rb +0 -10
  21. data/lib/rack/web_profiler/controller.rb +69 -64
  22. data/lib/rack/web_profiler/engine.rb +15 -6
  23. data/lib/rack/web_profiler/model/collection_record.rb +1 -0
  24. data/lib/rack/web_profiler/request.rb +5 -1
  25. data/lib/rack/web_profiler/router.rb +1 -1
  26. data/lib/rack/web_profiler/version.rb +1 -1
  27. data/lib/rack/web_profiler/view.rb +236 -0
  28. data/lib/rack/web_profiler.rb +34 -17
  29. data/rack-webprofiler.gemspec +1 -0
  30. metadata +19 -10
  31. data/lib/rack/web_profiler/auto_configure/rails.rb +0 -12
  32. data/lib/rack/web_profiler/collector/rails/active_record_collector.rb +0 -25
  33. data/lib/rack/web_profiler/collector/rails/logger_collector.rb +0 -22
  34. data/lib/rack/web_profiler/collector/rails/rails_collector.rb +0 -25
  35. data/lib/rack/web_profiler/collector/rails/request_collector.rb +0 -50
  36. data/lib/rack/web_profiler/collector/sinatra/request_collector.rb +0 -216
  37. data/lib/rack/web_profiler/collector/sinatra/sinatra_collector.rb +0 -25
  38. data/lib/rack/web_profiler/erb.rb +0 -9
@@ -18,11 +18,11 @@ ICON
18
18
  store :request_cookies, request.cookies
19
19
  store :request_get, request.GET
20
20
  store :request_post, get_request_post(request)
21
- store :request_session, request.session
21
+ store :request_session, hash_to_s(request.session)
22
22
  store :request_cookies, request.cookies
23
23
  store :request_body, get_request_body(request)
24
24
 
25
- store :rack_env, {} # request.env.each { |k, v| v.inspect }
25
+ store :rack_env, hash_to_s(request.env)
26
26
 
27
27
  store :response_status, response.status
28
28
  store :response_headers, response.headers
@@ -38,8 +38,6 @@ ICON
38
38
 
39
39
  template __FILE__, type: :DATA
40
40
 
41
- is_enabled? -> { defined?(Rack) && !defined?(Rails) && !defined?(Sinatra) }
42
-
43
41
  class << self
44
42
  # Get request headers.
45
43
  #
@@ -57,22 +55,27 @@ ICON
57
55
  end
58
56
 
59
57
  def get_request_body(request)
60
- return nil if request.body.nil?
61
- request.body.gets
58
+ return nil if request.body.nil? || request.get?
59
+ body = request.body.dup
60
+ body.read
61
+ end
62
+
63
+ def hash_to_s(hash)
64
+ hash.collect {|k,v| [k, v.to_s]}
62
65
  end
63
66
  end
64
67
  end
65
68
  end
66
69
 
67
70
  __END__
68
- <% content_for :tab do %>
69
- <%= data[:response_status] %> | <%= data[:request_method] %> <%= data[:request_path] %>
71
+ <% tab_content do %>
72
+ <%=h data(:response_status) %>
70
73
  <% end %>
71
74
 
72
- <% content_for :panel do %>
75
+ <% panel_content do %>
73
76
  <div class="block">
74
77
  <h3>GET</h3>
75
- <% unless data[:request_get].empty? %>
78
+ <% unless data(:request_get).empty? %>
76
79
  <table>
77
80
  <thead>
78
81
  <tr>
@@ -81,10 +84,10 @@ __END__
81
84
  </tr>
82
85
  <thead>
83
86
  <tbody>
84
- <% data[:request_get].each do |k, v| %>
87
+ <% data(:request_get).each do |k, v| %>
85
88
  <tr>
86
- <th><%= k %></th>
87
- <td class="code"><%= v %></td>
89
+ <th><%=h k %></th>
90
+ <td class="code"><%=h v %></td>
88
91
  </tr>
89
92
  <% end %>
90
93
  </tbody>
@@ -96,7 +99,7 @@ __END__
96
99
 
97
100
  <div class="block">
98
101
  <h3>POST</h3>
99
- <% if data[:request_post] && !data[:request_post].empty? %>
102
+ <% if data(:request_post) && !data(:request_post).empty? %>
100
103
  <table>
101
104
  <thead>
102
105
  <tr>
@@ -105,10 +108,10 @@ __END__
105
108
  </tr>
106
109
  <thead>
107
110
  <tbody>
108
- <% data[:request_post].each do |k, v| %>
111
+ <% data(:request_post).each do |k, v| %>
109
112
  <tr>
110
- <th><%= k %></th>
111
- <td class="code"><%= v %></td>
113
+ <th><%=h k %></th>
114
+ <td class="code"><%=h v %></td>
112
115
  </tr>
113
116
  <% end %>
114
117
  </tbody>
@@ -120,7 +123,7 @@ __END__
120
123
 
121
124
  <div class="block">
122
125
  <h3>Request headers</h3>
123
- <% unless data[:request_headers].empty? %>
126
+ <% unless data(:request_headers).empty? %>
124
127
  <table>
125
128
  <thead>
126
129
  <tr>
@@ -129,10 +132,10 @@ __END__
129
132
  </tr>
130
133
  <thead>
131
134
  <tbody>
132
- <% data[:request_headers].sort.each do |k, v| %>
135
+ <% data(:request_headers).sort.each do |k, v| %>
133
136
  <tr>
134
- <th><%= k %></th>
135
- <td class="code"><%= v %></td>
137
+ <th><%=h k %></th>
138
+ <td class="code"><%=h v %></td>
136
139
  </tr>
137
140
  <% end %>
138
141
  </tbody>
@@ -144,8 +147,8 @@ __END__
144
147
 
145
148
  <div class="block">
146
149
  <h3>Request content</h3>
147
- <% unless data[:request_body].nil? %>
148
- <code><%= data[:request_body] %></code>
150
+ <% unless data(:request_body).nil? %>
151
+ <%=highlight code: data(:request_body) %>
149
152
  <% else %>
150
153
  <p><span class="text__no-value">No request content</span></p>
151
154
  <% end %>
@@ -153,7 +156,7 @@ __END__
153
156
 
154
157
  <div class="block">
155
158
  <h3>Response headers</h3>
156
- <% unless data[:response_headers].empty? %>
159
+ <% unless data(:response_headers).empty? %>
157
160
  <table>
158
161
  <thead>
159
162
  <tr>
@@ -162,7 +165,7 @@ __END__
162
165
  </tr>
163
166
  <thead>
164
167
  <tbody>
165
- <% data[:response_headers].sort.each do |k, v| %>
168
+ <% data(:response_headers).sort.each do |k, v| %>
166
169
  <tr>
167
170
  <th><%= k %></th>
168
171
  <td class="code"><%= v %></td>
@@ -177,7 +180,7 @@ __END__
177
180
 
178
181
  <div class="block">
179
182
  <h3>Session</h3>
180
- <% unless data[:request_session].empty? %>
183
+ <% unless data(:request_session).empty? %>
181
184
  <table>
182
185
  <thead>
183
186
  <tr>
@@ -186,7 +189,7 @@ __END__
186
189
  </tr>
187
190
  <thead>
188
191
  <tbody>
189
- <% data[:request_session].each do |k, v| %>
192
+ <% data(:request_session).each do |k, v| %>
190
193
  <tr>
191
194
  <th><%= k %></th>
192
195
  <td class="code"><%= v %></td>
@@ -201,7 +204,7 @@ __END__
201
204
 
202
205
  <div class="block">
203
206
  <h3>Cookies</h3>
204
- <% unless data[:request_cookies].empty? %>
207
+ <% unless data(:request_cookies).empty? %>
205
208
  <table>
206
209
  <thead>
207
210
  <tr>
@@ -210,10 +213,10 @@ __END__
210
213
  </tr>
211
214
  <thead>
212
215
  <tbody>
213
- <% data[:request_cookies].each do |k, v| %>
216
+ <% data(:request_cookies).each do |k, v| %>
214
217
  <tr>
215
- <th><%= k %></th>
216
- <td class="code"><%= v %></td>
218
+ <th><%=h k %></th>
219
+ <td class="code"><%=h v %></td>
217
220
  </tr>
218
221
  <% end %>
219
222
  </tbody>
@@ -225,7 +228,7 @@ __END__
225
228
 
226
229
  <div class="block">
227
230
  <h3>Env</h3>
228
- <% if data[:rack_env] && !data[:rack_env].empty? %>
231
+ <% if data(:rack_env) && !data(:rack_env).empty? %>
229
232
  <table>
230
233
  <thead>
231
234
  <tr>
@@ -234,10 +237,10 @@ __END__
234
237
  </tr>
235
238
  <thead>
236
239
  <tbody>
237
- <% data[:rack_env].each do |k, v| %>
240
+ <% data(:rack_env).sort.each do |k, v| %>
238
241
  <tr>
239
- <th><%= k %></th>
240
- <td class="code"><%= v %></td>
242
+ <th><%=h k %></th>
243
+ <td class="code"><%=h v %></td>
241
244
  </tr>
242
245
  <% end %>
243
246
  </tbody>
@@ -41,21 +41,21 @@ ICON
41
41
  end
42
42
 
43
43
  __END__
44
- <% content_for :tab do %>
45
- <%= data[:ruby_version] %>
44
+ <% tab_content do %>
45
+ <%=h data(:ruby_version) %>
46
46
  <% end %>
47
47
 
48
- <% content_for :panel do %>
48
+ <% panel_content do %>
49
49
  <div class="block">
50
50
  <h3>Ruby informations</h3>
51
51
  <table>
52
52
  <tr>
53
53
  <th>Version</th>
54
- <td><%= "#{data[:ruby_version]}p#{data[:ruby_patchlevel]} (#{data[:ruby_release_date]} revision #{data[:ruby_revision]}) [#{data[:ruby_platform]}]" %></td>
54
+ <td><%=h "#{data(:ruby_version)}p#{data(:ruby_patchlevel)} (#{data(:ruby_release_date)} revision #{data(:ruby_revision)}) [#{data(:ruby_platform)}]" %></td>
55
55
  </tr>
56
56
  <tr>
57
57
  <th>Documentation</th>
58
- <td><a href="<%= data[:ruby_doc_url] %>"><%= data[:ruby_doc_url] %></a></td>
58
+ <td><a href="<%=h data(:ruby_doc_url) %>"><%= data(:ruby_doc_url) %></a></td>
59
59
  </tr>
60
60
  </table>
61
61
  </div>
@@ -67,13 +67,15 @@ __END__
67
67
  <tr>
68
68
  <th>Name</th>
69
69
  <th>Version</th>
70
+ <th>Summary</th>
70
71
  </tr>
71
72
  <thead>
72
73
  <tbody>
73
- <% data[:gems_list].sort!{|a,b| a[:name] <=> b[:name] }.each do |g| %>
74
+ <% data(:gems_list).sort!{|a,b| a[:name] <=> b[:name] }.each do |g| %>
74
75
  <tr>
75
- <th><%= g[:name] %></th>
76
+ <th><a href="<%= g[:homepage] %>"><%= g[:name] %></a></th>
76
77
  <td><%= g[:version] %></td>
78
+ <td><%= g[:summary] %></td>
77
79
  </tr>
78
80
  <% end %>
79
81
  </tbody>
@@ -20,6 +20,6 @@ ICON
20
20
  end
21
21
 
22
22
  __END__
23
- <% content_for :tab do %>
24
- <%= (data[:runtime] * 1000.0).round(2) %> ms
23
+ <% tab_content do %>
24
+ <%= (data(:runtime) * 1000.0).round(2) %> ms
25
25
  <% end %>
@@ -0,0 +1,44 @@
1
+ module Rack
2
+ class WebProfiler::Collector::View < WebProfiler::View
3
+
4
+ def context
5
+ @context ||= Context.new
6
+ end
7
+
8
+ # Helpers
9
+ module Helpers
10
+
11
+ def tab_content
12
+ if block_given?
13
+ @tab_content ||= capture(&Proc.new)
14
+ elsif !@tab_content.nil?
15
+ @tab_content
16
+ end
17
+ end
18
+
19
+ def panel_content
20
+ if block_given?
21
+ @panel_content ||= capture(&Proc.new)
22
+ elsif !@panel_content.nil?
23
+ @panel_content
24
+ end
25
+ end
26
+
27
+ def data(k)
28
+ return nil if @collection.nil?
29
+
30
+ datas = @collection.datas[@collector.name.to_sym][:datas]
31
+ return datas[k] if datas.has_key?(k)
32
+
33
+ nil
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ class Context
40
+ include WebProfiler::View::CommonHelpers
41
+ include Helpers
42
+ end
43
+ end
44
+ end
@@ -6,24 +6,13 @@ module Rack
6
6
  class WebProfiler::Collector
7
7
  autoload :RubyCollector, "rack/web_profiler/collector/ruby_collector"
8
8
  autoload :TimeCollector, "rack/web_profiler/collector/time_collector"
9
+ autoload :View, "rack/web_profiler/collector/view"
9
10
 
10
11
  module Rack
11
12
  autoload :RackCollector, "rack/web_profiler/collector/rack/rack_collector"
12
13
  autoload :RequestCollector, "rack/web_profiler/collector/rack/request_collector"
13
14
  end
14
15
 
15
- module Rails
16
- autoload :ActiveRecordCollector, "rack/web_profiler/collector/rails/active_record_collector"
17
- autoload :LoggerCollector, "rack/web_profiler/collector/rails/logger_collector"
18
- autoload :RailsCollector, "rack/web_profiler/collector/rails/rails_collector"
19
- autoload :RequestCollector, "rack/web_profiler/collector/rails/request_collector"
20
- end
21
-
22
- module Sinatra
23
- autoload :RequestCollector, "rack/web_profiler/collector/sinatra/request_collector"
24
- autoload :SinatraCollector, "rack/web_profiler/collector/sinatra/sinatra_collector"
25
- end
26
-
27
16
  # DSL
28
17
  module DSL
29
18
  def self.included(base)
@@ -104,8 +93,10 @@ module Rack
104
93
  attr_reader :datas
105
94
 
106
95
  def initialize
107
- @datas = Hash.new
108
- @status = nil
96
+ @datas = Hash.new
97
+ @status = nil
98
+ @show_tab = true
99
+ @show_panel = true
109
100
  end
110
101
 
111
102
  # Store a value.
@@ -129,13 +120,35 @@ module Rack
129
120
  @status
130
121
  end
131
122
 
123
+ #
124
+ #
125
+ # @param b [Boolean, nil]
126
+ #
127
+ # @return [Boolean]
128
+ def show_panel(b = nil)
129
+ @show_panel = !!b unless b.nil?
130
+ @show_panel
131
+ end
132
+
133
+ #
134
+ #
135
+ # @param b [Boolean, nil]
136
+ #
137
+ # @return [Boolean]
138
+ def show_tab(b = nil)
139
+ @show_tab = !!b unless b.nil?
140
+ @show_tab
141
+ end
142
+
132
143
  # Transform DataStorage to an Hash
133
144
  #
134
145
  # @return [Hash<Symbol, Object>]
135
146
  def to_h
136
147
  {
137
- datas: @datas,
138
- status: @status
148
+ datas: @datas,
149
+ status: @status,
150
+ show_panel: @show_panel,
151
+ show_tab: @show_tab,
139
152
  }
140
153
  end
141
154
  end
@@ -13,16 +13,6 @@ module Rack
13
13
  # Rack
14
14
  # Rack::WebProfiler::Collector::Rack::RackCollector,
15
15
  Rack::WebProfiler::Collector::Rack::RequestCollector,
16
-
17
- # Rails
18
- # Rack::WebProfiler::Collector::Rails::ActiveRecordCollector,
19
- # Rack::WebProfiler::Collector::Rails::LoggerCollector,
20
- Rack::WebProfiler::Collector::Rails::RailsCollector,
21
- Rack::WebProfiler::Collector::Rails::RequestCollector,
22
-
23
- # Sinatra
24
- Rack::WebProfiler::Collector::Sinatra::RequestCollector,
25
- Rack::WebProfiler::Collector::Sinatra::SinatraCollector,
26
16
  ].freeze
27
17
  def initialize
28
18
  @collectors = Rack::WebProfiler::Collectors.new
@@ -10,55 +10,61 @@ module Rack
10
10
  #
11
11
  # @param request [Rack::WebProfiler::Request]
12
12
  def initialize(request)
13
- @request = request
14
- @contents_for = {}
13
+ @request = request
15
14
  end
16
15
 
17
16
  # List the webprofiler history.
17
+ #
18
+ # @return [Rack::Response]
18
19
  def index
19
20
  @collections = Rack::WebProfiler::Model::CollectionRecord.order(Sequel.desc(:created_at))
20
21
  .limit(20)
21
22
 
23
+ return json(@collections, 200, {only: [:token, :http_method, :http_status, :url, :ip]}) if prefer_json?
24
+ return json(@collections, to_json_opts: {only: [:token, :http_method, :http_status, :url, :ip]}) if prefer_json?
22
25
  erb "panel/index.erb", layout: "panel/layout.erb"
23
26
  end
24
27
 
25
28
  # Show the webprofiler panel.
29
+ #
30
+ # @param token [String] The collection token
31
+ #
32
+ # @return [Rack::Response]
26
33
  def show(token)
27
34
  @collection = Rack::WebProfiler::Model::CollectionRecord[token: token]
28
- return error404 if @collection.nil?
35
+ return not_found if @collection.nil?
29
36
 
30
37
  @collectors = Rack::WebProfiler.config.collectors.all
31
38
  @collector = nil
32
39
 
33
40
  unless @request.params['panel'].nil?
34
41
  @collector = @collectors[@request.params['panel'].to_sym]
35
- end
36
-
37
- if @collector.nil?
42
+ else
38
43
  @collector = @collectors.values.first
39
44
  end
45
+ return not_found if @collector.nil?
40
46
 
41
- @current_panel = @collector.name
42
-
43
- # @todo return json if request.content_type ask json (same for xml?)
44
- # @example json(@collectors) if @request.media_type.include? "json"
45
-
47
+ return json(@collection) if prefer_json?
46
48
  erb "panel/show.erb", layout: "panel/layout.erb"
47
49
  end
48
50
 
49
- # Print the webprofiler toolbar
51
+ # Print the webprofiler toolbar.
52
+ #
53
+ # @param token [String] The collection token
54
+ #
55
+ # @return [Rack::Response]
50
56
  def show_toolbar(token)
51
57
  @collection = Rack::WebProfiler::Model::CollectionRecord[token: token]
52
58
  return erb nil, status: 404 if @collection.nil?
53
59
 
54
60
  @collectors = Rack::WebProfiler.config.collectors.all
55
- # @todo process the callector views
56
- # @collectors = Rack::WebProfiler::Collector.render_tabs(@record)
57
61
 
58
62
  erb "profiler.erb"
59
63
  end
60
64
 
61
65
  # Clean the webprofiler.
66
+ #
67
+ # @return [Rack::Response]
62
68
  def delete
63
69
  Rack::WebProfiler::Model.clean
64
70
 
@@ -67,30 +73,62 @@ module Rack
67
73
 
68
74
  private
69
75
 
76
+ # Is "application/json" reponse is prefered?
77
+ #
78
+ # @return [Boolean]
79
+ #
80
+ # @private
81
+ def prefer_json?
82
+ prefered_http_accept == "application/json"
83
+ end
84
+
85
+ # Returns the prefered Content-Type response between html and json.
86
+ #
87
+ # @return [String]
88
+ #
89
+ # @private
90
+ def prefered_http_accept
91
+ Rack::Utils.best_q_match(@request.env["HTTP_ACCEPT"], %w[text/html application/json])
92
+ end
93
+
94
+ # Redirection.
95
+ #
96
+ # @param path [string]
97
+ #
98
+ # @return [Rack::Response]
99
+ #
100
+ # @private
70
101
  def redirect(path)
71
102
  Rack::Response.new([], 302, {
72
103
  "Location" => "#{@request.base_url}#{path}",
73
104
  })
74
105
  end
75
106
 
107
+ # 404 page.
108
+ #
109
+ # @return [Rack::Response]
110
+ #
111
+ # @private
112
+ def not_found
113
+ erb "404.erb", layout: "panel/layout.erb", status: 404
114
+ end
115
+
76
116
  # Render a HTML reponse from an ERB template.
77
117
  #
78
118
  # @param path [String] Path to the ERB template
119
+ # @option layout [String, nil] Path to the ERB layout
120
+ # @option variables [Hash, nil] List of variables to the view
121
+ # @option status [Integer] HTTP status code
79
122
  #
80
123
  # @return [Rack::Response]
81
- def erb(path, layout: nil, status: 200)
82
- content = ""
83
-
84
- unless path.nil?
85
- templates = [read_template(path)]
86
- templates << read_template(layout) unless layout.nil?
124
+ #
125
+ # @private
126
+ def erb(path, layout: nil, variables: nil, status: 200)
127
+ v = WebProfiler::View.new(path, layout: layout)
87
128
 
88
- content = templates.inject(nil) do |prev, temp|
89
- _render_erb(temp) { prev }
90
- end
91
- end
129
+ variables ||= binding
92
130
 
93
- Rack::Response.new(content, status, {
131
+ Rack::Response.new(v.result(variables), status, {
94
132
  "Content-Type" => "text/html",
95
133
  })
96
134
  end
@@ -98,49 +136,16 @@ module Rack
98
136
  # Render a JSON response from an Array or a Hash.
99
137
  #
100
138
  # @param data [Array, Hash] Data
139
+ # @param status [Integer]
140
+ # @param opts [Hash]
101
141
  #
102
142
  # @return [Rack::Response]
103
- def json(data = {})
104
- Rack::Response.new(data.to_json, 200, {
143
+ #
144
+ # @private
145
+ def json(data = {}, status: 200, to_json_opts: {})
146
+ Rack::Response.new(data.send(:to_json, opts), status, {
105
147
  "Content-Type" => "application/json",
106
148
  })
107
149
  end
108
-
109
- def error404
110
- erb "404.erb", layout: "panel/layout.erb", status: 404
111
- end
112
-
113
- def _render_erb(template)
114
- ERB.new(template).result(binding)
115
- end
116
-
117
- def partial(path)
118
- return "" if path.nil?
119
- ERB.new(read_template(path)).result(binding)
120
- end
121
-
122
- def render_collector(collector, data)
123
- @data = data
124
- return "" if collector.nil?
125
- ERB.new(read_template(collector.template)).result(binding)
126
- end
127
-
128
- def content_for(name)
129
- name = name.to_sym
130
-
131
- if block_given?
132
- @contents_for[name] = Proc.new
133
- elsif @contents_for[name].respond_to?(:call)
134
- @contents_for[name].call
135
- end
136
- end
137
-
138
- def read_template(template)
139
- unless template.empty?
140
- path = ::File.expand_path("../../templates/#{template}", __FILE__)
141
- return ::File.read(path) if ::File.exist?(path)
142
- end
143
- template
144
- end
145
150
  end
146
151
  end
@@ -2,7 +2,7 @@ module Rack
2
2
  #
3
3
  class WebProfiler::Engine
4
4
  class << self
5
- # Process
5
+ # Process request.
6
6
  #
7
7
  # @param request [Rack::WebProfiler::Request]
8
8
  # @param body
@@ -22,7 +22,7 @@ module Rack
22
22
  response = Rack::Response.new([], status, headers)
23
23
 
24
24
  response.header["X-RackWebProfiler-Token"] = @token
25
- response.header["X-RackWebProfiler-Url"] = @url
25
+ response.header["X-RackWebProfiler-Url"] = WebProfiler::Router.url_for_profiler(record.token)
26
26
 
27
27
  if defined? Rails and body.is_a? ActionDispatch::Response::RackBody
28
28
  body = body.body
@@ -37,12 +37,21 @@ module Rack
37
37
  response
38
38
  end
39
39
 
40
+ # Process an exception.
41
+ #
42
+ # @param request [Rack::WebProfiler::Request]
43
+ #
44
+ # @return [Rack::Response]
45
+ def process_exception(request)
46
+ process(request, [], 500, {})
47
+ end
48
+
40
49
  private
41
50
 
42
51
  # Collect
43
52
  #
44
- # @param request
45
- # @param response
53
+ # @param request [Rack::WebProfiler::Request]
54
+ # @param response [Rack::Response]
46
55
  def collect!(request, response)
47
56
  processor = Processor.new(request, response)
48
57
  processor.save!
@@ -61,7 +70,7 @@ module Rack
61
70
  #
62
71
  # @return [String]
63
72
  def template
64
- @template ||= ERB.new(::File.read(::File.expand_path("../../templates/async.erb", __FILE__)))
73
+ @template ||= WebProfiler::View.new("async.erb")
65
74
  end
66
75
 
67
76
  class Processor
@@ -85,7 +94,7 @@ module Rack
85
94
 
86
95
  def create_record!
87
96
  @record ||= WebProfiler::Model::CollectionRecord.create({
88
- url: @request.path,
97
+ url: @request.url,
89
98
  ip: @request.ip,
90
99
  http_method: @request.request_method,
91
100
  http_status: @response.status,
@@ -5,6 +5,7 @@ module Rack
5
5
  plugin :schema
6
6
  plugin :hook_class_methods
7
7
  plugin :serialization
8
+ plugin :json_serializer
8
9
  plugin :timestamps
9
10
 
10
11
  # Attributes:
@@ -1,7 +1,7 @@
1
1
  module Rack
2
2
  #
3
3
  class WebProfiler::Request < Rack::Request
4
- attr_reader :runtime
4
+ attr_reader :runtime, :exception
5
5
 
6
6
  def start_runtime!
7
7
  @request_start ||= Time.now.to_f
@@ -10,5 +10,9 @@ module Rack
10
10
  def save_runtime!
11
11
  @runtime ||= Time.now.to_f - @request_start
12
12
  end
13
+
14
+ def save_exception(e)
15
+ @exception = e
16
+ end
13
17
  end
14
18
  end