Commit 95b2202f7419d9571cc6a6a1d2b533dac5950c60
Exists in
master
and in
1 other branch
Merge pull request #697 from phoet/add_to_curl_to_summary
Add to curl to summary
Showing
4 changed files
with
26 additions
and
1 deletions
Show diff stats
app/models/notice.rb
| @@ -78,6 +78,16 @@ class Notice | @@ -78,6 +78,16 @@ class Notice | ||
| 78 | "N/A" | 78 | "N/A" |
| 79 | end | 79 | end |
| 80 | 80 | ||
| 81 | + def to_curl | ||
| 82 | + headers = %w(Accept Accept-Encoding Accept-Language Cookie Referer User-Agent).each_with_object([]) do |name, h| | ||
| 83 | + if value = env_vars["HTTP_#{name.underscore.upcase}"] | ||
| 84 | + h << "-H '#{name}: #{value}'" | ||
| 85 | + end | ||
| 86 | + end | ||
| 87 | + | ||
| 88 | + "curl -X #{env_vars['REQUEST_METHOD'] || 'GET'} #{headers.join(' ')} #{request['url']}" | ||
| 89 | + end | ||
| 90 | + | ||
| 81 | def env_vars | 91 | def env_vars |
| 82 | request['cgi-data'] || {} | 92 | request['cgi-data'] || {} |
| 83 | end | 93 | end |
app/views/notices/_summary.html.haml
| @@ -10,6 +10,9 @@ | @@ -10,6 +10,9 @@ | ||
| 10 | %tr | 10 | %tr |
| 11 | %th URL | 11 | %th URL |
| 12 | %td.nowrap= link_to notice.request['url'], notice.request['url'] | 12 | %td.nowrap= link_to notice.request['url'], notice.request['url'] |
| 13 | + %tr | ||
| 14 | + %th | ||
| 15 | + %td= notice.to_curl | ||
| 13 | %tr | 16 | %tr |
| 14 | %th Where | 17 | %th Where |
| 15 | %td= notice.where | 18 | %td= notice.where |
lib/tasks/errbit/demo.rake
| @@ -49,7 +49,8 @@ namespace :errbit do | @@ -49,7 +49,8 @@ namespace :errbit do | ||
| 49 | :backtrace => random_backtrace, | 49 | :backtrace => random_backtrace, |
| 50 | :request => { | 50 | :request => { |
| 51 | 'component' => 'main', | 51 | 'component' => 'main', |
| 52 | - 'action' => 'error' | 52 | + 'action' => 'error', |
| 53 | + 'url' => "http://example.com/post/#{[111, 222, 333].sample}", | ||
| 53 | }, | 54 | }, |
| 54 | :server_environment => {'environment-name' => Rails.env.to_s}, | 55 | :server_environment => {'environment-name' => Rails.env.to_s}, |
| 55 | :notifier => {:name => "seeds.rb"}, | 56 | :notifier => {:name => "seeds.rb"}, |
spec/models/notice_spec.rb
| @@ -35,6 +35,17 @@ describe Notice do | @@ -35,6 +35,17 @@ describe Notice do | ||
| 35 | end | 35 | end |
| 36 | end | 36 | end |
| 37 | 37 | ||
| 38 | + context "to_curl" do | ||
| 39 | + let(:request) { {'url' => "http://example.com/resource/12", 'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0'}} } | ||
| 40 | + let(:notice) { Fabricate.build(:notice, request: request) } | ||
| 41 | + | ||
| 42 | + it 'has a curl representation' do | ||
| 43 | + cmd = notice.to_curl | ||
| 44 | + | ||
| 45 | + cmd.should eql(%q[curl -X GET -H 'User-Agent: Mozilla/5.0' http://example.com/resource/12]) | ||
| 46 | + end | ||
| 47 | + end | ||
| 48 | + | ||
| 38 | describe "user agent" do | 49 | describe "user agent" do |
| 39 | it "should be parsed and human-readable" do | 50 | it "should be parsed and human-readable" do |
| 40 | notice = Fabricate.build(:notice, :request => {'cgi-data' => { | 51 | notice = Fabricate.build(:notice, :request => {'cgi-data' => { |