Class: Tap::Http::Capture
- Inherits:
-
Controller
- Object
- Controller
- Tap::Http::Capture
- Includes:
- Utils, Ubiquity::Utils
- Defined in:
- lib/tap/http/capture.rb
Overview
::controller ::ubiquity
Constant Summary collapse
- PREFIX =
'__redirect_http_'
- REDIRECT_PARAMETER =
'__redirect_http_original_action'
Constants included from Utils
Instance Method Summary collapse
- #create(id) ⇒ Object
- #destroy(id) ⇒ Object
- #download(id) ⇒ Object
-
#http ⇒ Object
Parses HTTP request.
-
#index ⇒ Object
Brings up the tutorial.
-
#redirect_http ⇒ Object
Returns the redirection script.
-
#say ⇒ Object
Say is the target of the tutorial.
- #show(id) ⇒ Object
-
#tutorial ⇒ Object
Brings up a tutorial teaching how to capture and resubmit forms.
- #update(id = "request") ⇒ Object
Methods included from Utils
each_member, headerize, parse_http_request, parse_multipart, parse_rack_request, parse_webrick_request, splat
Instance Method Details
#create(id) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/tap/http/capture.rb', line 21 def create(id) persistence.create(id) do |io| io << YAML.dump([parse_request]) end download(id) end |
#destroy(id) ⇒ Object
54 55 56 57 |
# File 'lib/tap/http/capture.rb', line 54 def destroy(id) persistence.destroy(id) index end |
#download(id) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/tap/http/capture.rb', line 33 def download(id) path = persistence.path(id) filename = id filename += ".yml" if File.extname(id) == "" response['Content-Type'] = "text/plain" response['Content-Disposition'] = "attachment; filename=#{filename};" persistence.read(id) end |
#http ⇒ Object
Parses HTTP request
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/tap/http/capture.rb', line 108 def http if request.get? render 'http.erb' else keep_content = request.params['keep_content'] == "true" hash = {} parse_http_request(request.params['http'], keep_content).each_pair do |key, value| hash[key.to_s] = value end # remove extranous data hash.delete('headers') hash.delete('version') response['Content-Type'] = "text/plain" YAML.dump(hash) end end |
#index ⇒ Object
Brings up the tutorial.
17 18 19 |
# File 'lib/tap/http/capture.rb', line 17 def index render 'index.erb', :locals => {:captures => persistence.index } end |
#redirect_http ⇒ Object
Returns the redirection script.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tap/http/capture.rb', line 73 def redirect_http style = render 'redirect.css' script = render 'redirect.js', :locals => { :redirect_parameter => REDIRECT_PARAMETER, :redirect_action => uri(:update), :header => render('header.erb'), :footer => render('footer.erb') } if request.get? response['Content-Type'] = 'text/plain' %Q{ <style type="text/css"> #{style.strip} </style> <script type="text/javascript"> #{script.strip} </script>} else response['Content-Type'] = 'text/javascript' %Q{ var style = document.createElement("style"); style.type = "text/css"; style.innerHTML = #{style.to_json}; document.body.appendChild(style); var script = document.createElement("script"); script.type = "text/javascript"; script.innerHTML = #{script.to_json}; document.body.appendChild(script); } end end |
#say ⇒ Object
Say is the target of the tutorial.
68 69 70 |
# File 'lib/tap/http/capture.rb', line 68 def say "<pre>#{request.params['words']}</pre>" end |
#show(id) ⇒ Object
28 29 30 31 |
# File 'lib/tap/http/capture.rb', line 28 def show(id) response['Content-Type'] = "text/plain" persistence.read(id) end |
#tutorial ⇒ Object
Brings up a tutorial teaching how to capture and resubmit forms.
60 61 62 63 64 65 |
# File 'lib/tap/http/capture.rb', line 60 def tutorial serve js_injection(:redirect_http) do |link| content = render 'tutorial.erb' content + link end end |
#update(id = "request") ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tap/http/capture.rb', line 43 def update(id="request") path = persistence.path(id) requests = File.exists?(path) ? YAML.load_file(path) : [] requests << parse_request persistence.update(id) do |io| io << YAML.dump(requests) end download(id) end |