Commit bb3af8d24bf700d996471d7e851fefb1020ace72
1 parent
5b949712
Exists in
master
and in
1 other branch
add a to_curl to notice and show on summary
Showing
3 changed files
with
24 additions
and
0 deletions
Show diff stats
app/models/notice.rb
| ... | ... | @@ -78,6 +78,16 @@ class Notice |
| 78 | 78 | "N/A" |
| 79 | 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 | 91 | def env_vars |
| 82 | 92 | request['cgi-data'] || {} |
| 83 | 93 | end | ... | ... |
app/views/notices/_summary.html.haml
spec/models/notice_spec.rb
| ... | ... | @@ -35,6 +35,17 @@ describe Notice do |
| 35 | 35 | end |
| 36 | 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 | 49 | describe "user agent" do |
| 39 | 50 | it "should be parsed and human-readable" do |
| 40 | 51 | notice = Fabricate.build(:notice, :request => {'cgi-data' => { | ... | ... |