Permalink
Browse files

will actually compare different groups of requests

  • Loading branch information...
1 parent 5994415 commit 385f5801e62970efd59fbb84e5accf9dccacbfa5 @schacon committed Apr 29, 2010
Showing with 92 additions and 7 deletions.
  1. +20 −6 browser/browser.rb
  2. +12 −1 browser/views/compare.erb
  3. +60 −0 browser/views/compare_detail.erb
View
@@ -35,19 +35,20 @@ def process_http(req)
http = headers.shift
harr = headers.map { |h| h.split(': ') }
+ r = ""
begin
req = REXML::Document.new(xml)
- r = ""
req.write(r, 3)
div = CodeRay.scan(r, :xml).div
rescue
div = CodeRay.scan(xml, :xml).div
end
begin
- n = Nokogiri.XML(xml)
+ n = Nokogiri.XML(r)
values = get_values([n.root.name], n.root, [])
- rescue
+ rescue Object => e
+ puts e.message
values = []
end
@@ -68,9 +69,10 @@ def url_filter(url, id)
base = @vars[group]['base']
act = @vars[group]['act']
ver = @vars[group]['ver']
- url = url.gsub(base, '<span class="base">[base]</span>')
- url = url.gsub(act, '<span class="act">[act]</span>')
- url = url.gsub(ver, '<span class="ver">[ver]</span>')
+ url = url.gsub(base, '<span class="base">[base]</span>') if base
+ url = url.gsub(act, '<span class="act">[act]</span>') if act
+ url = url.gsub(ver, '<span class="ver">[ver]</span>') if ver
+ url
end
get '/' do
@@ -143,6 +145,18 @@ def url_filter(url, id)
erb :compare
end
+get '/comparetwo/:one/:two' do
+ @snifter = Snifter.new
+ @sessions = []
+ [params[:one], params[:two]].each do |sess|
+ req, res = @snifter.session(sess)
+ req = process_http(req)
+ res = process_http(res)
+ @sessions << [req, res]
+ end
+ erb :compare_detail
+end
+
get '/clear_groups' do
Snifter.new.clear_groups
"cleared"
View
@@ -7,7 +7,7 @@
<% sess, req, res, time = data %>
<% sessB, reqB, resB, timeB = @compare[1][i] %>
<tr>
- <td rowspan="2"><input type="radio" name="compare"></td>
+ <td rowspan="2"><input rel="comparetwo/<%= sess %>/<%= sessB %>" class="comparetwo" type="radio" name="compare"></td>
<td><code><%= url_filter req, 0 %></code></td>
<td><%= res %></td>
</tr>
@@ -17,3 +17,14 @@
</tr>
<% end %>
</table>
+
+
+<div id="results"></div>
+
+<script type="text/javascript">
+ $(function(){
+ $(".comparetwo").click(function() {
+ $("#results").load($(this).attr('rel'))
+ })
+ })
+</script>
@@ -0,0 +1,60 @@
+<h1>Compare Detail</h1>
+
+<table><tr>
+<% @sessions.each do |req, res| %>
+ <td valign="top">
+
+ <h4><code><%= req[:http] %></code></h4>
+ <table cellspacing="0" cellpadding="0" class="headers">
+ <% req[:headers].each do |k, v| %>
+ <tr>
+ <th><%= k %></th>
+ <td><%= v %></td>
+ </tr>
+ <% end %>
+ </table>
+ <br/>
+ <table cellspacing="0" cellpadding="0" class="xmlbody">
+ <% req[:body_values].each do |k, v| %>
+ <tr>
+ <th><%= k %></th>
+ <td><%= v %></td>
+ </tr>
+ <% end %>
+ </table>
+
+ <div class="req-body" style="display: none">
+ <%= req[:body] %>
+ </div>
+ <a onClick="$('.req-body').toggle(); return false" href="#" id="view-req-body" class="details">details</a>
+
+ <hr/>
+
+ <table cellspacing="0" cellpadding="0" class="headers">
+ <% res[:headers].each do |k, v| %>
+ <tr>
+ <th><%= k %></th>
+ <td><%= v %></td>
+ </tr>
+ <% end %>
+ </table>
+ <br/>
+ <table cellspacing="0" cellpadding="0" class="xmlbody">
+ <% res[:body_values].each do |k, v| %>
+ <tr>
+ <th><%= k %></th>
+ <td><%= v %></td>
+ </tr>
+ <% end %>
+ </table>
+
+ <div class="res-body" style="display: none">
+ <%= res[:body] %>
+ <hr/>
+ <%= CGI::escapeHTML(res[:body_raw]) %>
+ </div>
+ <a onClick="$('.res-body').toggle(); return false" href="#" id="view-res-body" class="details">details</a>
+
+ </td>
+<% end %>
+</tr></table>

0 comments on commit 385f580

Please sign in to comment.