tap-http 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ <p>
2
+ This is a tutorial for capturing http requests for modification and/or
3
+ resubmission at a later date. First, get the environment right:
4
+ </p>
5
+
6
+ <ul>
7
+ <li>Be sure you're viewing this in <a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
8
+ <li>Install <a href="http://labs.mozilla.com/2008/08/introducing-ubiquity/">Ubiquity</a></li>
9
+ <li>Subscribe to the <a href="http://gist.github.com/25932">redirect-http</a> command</li>
10
+ </ul>
11
+
12
+ <p>
13
+ Now capture the request from this page (use the same procedure wherever
14
+ else you need to capture the parameters of a form):
15
+ </p>
16
+
17
+ <ul>
18
+ <li>Bring up Ubiquity in Firefox by pressing 'option+space'</li>
19
+ <li>Enter the command: redirect-http http://localhost:8080/capture/http_to_yaml</li>
20
+ </ul>
21
+
22
+ <p>
23
+ You should now see some notification that you're redirecting this page.
24
+ Write what you want to say, hit submit, then follow the instructions.
25
+ </p>
26
+
27
+ <form action='say'>
28
+ What you want to say: <input name='words' />
29
+ <input type="submit" value="submit">
30
+ </form>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tap-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Chiang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-17 00:00:00 -07:00
12
+ date: 2009-02-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.12.0
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.1
34
+ version:
25
35
  description:
26
36
  email: simon.a.chiang@gmail.com
27
37
  executables: []
@@ -33,13 +43,13 @@ extra_rdoc_files:
33
43
  - MIT-LICENSE
34
44
  - History
35
45
  files:
36
- - cgi/echo.rb
37
- - cgi/http_to_yaml.rb
38
- - cgi/parse_http.rb
39
- - lib/tap/http/dispatch.rb
46
+ - controllers/capture_controller.rb
47
+ - lib/tap/http/get.rb
48
+ - lib/tap/http/request.rb
49
+ - lib/tap/http/submit.rb
40
50
  - lib/tap/http/utils.rb
41
51
  - lib/tap/test/http_test.rb
42
- - lib/tap/test/http_test/requests.rb
52
+ - views/capture_controller/index.erb
43
53
  - tap.yml
44
54
  - README
45
55
  - MIT-LICENSE
data/cgi/echo.rb DELETED
@@ -1,24 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
3
- ####################################
4
- # Echos back the HTTP header and parameters as YAML.
5
- #
6
- # Copyright (c) 2008, Regents of the University of Colorado
7
- # Developer: Simon Chiang, Biomolecular Structure Program
8
- # Homepage: http://hsc-proteomics.ucdenver.edu/hansen_lab
9
- #
10
- ####################################
11
-
12
- require 'cgi'
13
- require 'tap/http/utils'
14
-
15
- cgi = CGI.new
16
- cgi.out("text/plain") do
17
- begin
18
- request = Tap::Http::Utils.parse_cgi_request(cgi)
19
- request[:headers].to_yaml + request[:params].to_yaml
20
- rescue
21
- "Error: #{$!.message}\n" +
22
- $!.backtrace.join("\n")
23
- end
24
- end
data/cgi/http_to_yaml.rb DELETED
@@ -1,108 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
3
- #################################################
4
- #
5
- # Echos back redirected HTTP requests as YAML, suitable for use with the Tap::Net::Submit
6
- # task. All HTTP parameters and headers are echoed back directly, except for the
7
- # '__original_action' parameter which is used in conjuction with the 'Referer' header to
8
- # reconstruct the original url of the request. The '__original_action' parameter is not echoed.
9
- #
10
- # For example:
11
- # __original_action Referer echoed url
12
- # http://www.example.com?key=value (any) http://www.example.com?key=value
13
- # /page http://www.example.com http://www.example.com/page
14
- #
15
- # Simply drop this script into a cgi directory, and send it a redirected request. See the
16
- # RedirectHTTP Firefox extension for a simple way of redirecting requests to this script.
17
- #
18
- # Developer: Simon Chiang, Biomolecular Structure Program
19
- # Homepage: http://tap.rubyforge.org
20
- # Licence: MIT-STYLE
21
- #
22
- # Copyright (c) 2008, Regents of the University of Colorado
23
- #
24
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this
25
- # software and associated documentation files (the "Software"), to deal in the Software
26
- # without restriction, including without limitation the rights to use, copy, modify, merge,
27
- # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
28
- # to whom the Software is furnished to do so, subject to the following conditions:
29
- #
30
- # The above copyright notice and this permission notice shall be included in all copies or
31
- # substantial portions of the Software.
32
- #
33
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
34
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
35
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
36
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
37
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
38
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
39
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
40
- # OTHER DEALINGS IN THE SOFTWARE.
41
- #
42
- #################################################
43
-
44
- require 'rubygems'
45
- require 'cgi'
46
- require 'yaml'
47
- require 'net/http'
48
- require 'tap/http/utils'
49
-
50
- # included to sort the hash keys
51
- class Hash
52
- def to_yaml( opts = {} )
53
- YAML::quick_emit( object_id, opts ) do |out|
54
- out.map( taguri, to_yaml_style ) do |map|
55
- sorted_keys = keys
56
- sorted_keys = begin
57
- sorted_keys.sort
58
- rescue
59
- sorted_keys.sort_by {|k| k.to_s} rescue sorted_keys
60
- end
61
-
62
- sorted_keys.each do |k|
63
- map.add( k, fetch(k) )
64
- end
65
- end
66
- end
67
- end
68
- end
69
-
70
- cgi = CGI.new("html3")
71
- begin
72
-
73
- #
74
- # gather configs
75
- #
76
-
77
- config = {}
78
- Tap::Http::Utils.parse_cgi_request(cgi).each_pair do |key, value|
79
- config[key.to_s] = value
80
- end
81
-
82
- original_action = config['params'].delete("__original_action").to_s
83
- referer = config['headers']['Referer'].to_s
84
- config['url'] = Tap::Http::Utils.determine_url(original_action, referer)
85
- config['headers']['Host'] = URI.parse(config['url']).host
86
-
87
- #
88
- # format output
89
- #
90
-
91
- # help = cgi.a(Tap::Http::Utils::HELP_URL) { "help" }
92
- # how_to_get_cookies = cgi.a(Tap::Http::Utils::COOKIES_HELP_URL) { "how to get cookies" }
93
- #
94
- # If you need cookies, see #{how_to_get_cookies} or the #{help}.
95
-
96
- cgi.out('text/plain') do
97
- %Q{# Copy and paste into a configuration file. Multiple configs
98
- # can be added to a single file to perform batch submission.
99
- - #{config.to_yaml[5..-1].gsub(/\n/, "\n ")}
100
- }
101
- end
102
-
103
- rescue
104
- cgi.out("text/plain") do
105
- "Error: #{$!.message}\n" +
106
- $!.backtrace.join("\n")
107
- end
108
- end
data/cgi/parse_http.rb DELETED
@@ -1,129 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
3
- #################################################
4
- #
5
- # Developer: Simon Chiang, Biomolecular Structure Program
6
- # Homepage: http://tap.rubyforge.org
7
- # Licence: MIT-STYLE
8
- #
9
- # Copyright (c) 2008, Regents of the University of Colorado
10
- #
11
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this
12
- # software and associated documentation files (the "Software"), to deal in the Software
13
- # without restriction, including without limitation the rights to use, copy, modify, merge,
14
- # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
15
- # to whom the Software is furnished to do so, subject to the following conditions:
16
- #
17
- # The above copyright notice and this permission notice shall be included in all copies or
18
- # substantial portions of the Software.
19
- #
20
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
- # OTHER DEALINGS IN THE SOFTWARE.
28
- #
29
- #################################################
30
-
31
- require 'rubygems'
32
- require 'cgi'
33
- require 'tap/http/utils'
34
-
35
- # included to sort the hash keys
36
- class Hash
37
- def to_yaml( opts = {} )
38
- YAML::quick_emit( object_id, opts ) do |out|
39
- out.map( taguri, to_yaml_style ) do |map|
40
- sorted_keys = keys
41
- sorted_keys = begin
42
- sorted_keys.sort
43
- rescue
44
- sorted_keys.sort_by {|k| k.to_s} rescue sorted_keys
45
- end
46
-
47
- sorted_keys.each do |k|
48
- map.add( k, fetch(k) )
49
- end
50
- end
51
- end
52
- end
53
- end
54
-
55
- cgi = CGI.new("html3")
56
- begin
57
-
58
- http_request_key = "http_request"
59
- http_request = cgi[http_request_key]
60
- http_request = http_request.respond_to?(:read) ? http_request.read : http_request.to_s
61
-
62
- case
63
- when http_request.strip.empty?
64
-
65
- cgi.out do
66
- cgi.html do
67
- cgi.body do %Q{
68
- <h1>Parse HTTP Parameters</h1>
69
-
70
- <p>Enter an HTTP request, like the ones you can capture using the
71
- <a href='https://addons.mozilla.org/en-US/firefox/addon/3829'>LiveHTTPHeaders</a> addon for
72
- <a href='http://www.mozilla.com/en-US/firefox/'>Firefox</a>.
73
- </p>
74
-
75
- <form action='' method='post'>
76
- <textarea rows='20' cols='60' name='#{http_request_key}'></textarea>
77
- <br/>
78
- <input type='submit' value='Parse'>
79
- </form>
80
-
81
- <p>Note the request must be properly formated. For example:</p>
82
-
83
- <pre>
84
- GET / HTTP/1.1
85
- Host: tap.rubyforge.org
86
- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
87
- Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
88
- Accept-Language: en-us,en;q=0.5
89
- Accept-Encoding: gzip,deflate
90
- Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
91
- Keep-Alive: 300
92
- Connection: keep-alive
93
- </pre>}
94
- end
95
- end
96
- end
97
-
98
- else
99
- config = {}
100
- Tap::Http::Utils.parse_http_request(http_request).each_pair do |key, value|
101
- config[key.to_s] = value
102
- end
103
-
104
- help = cgi.a(Tap::Http::Utils::HELP_URL) { "help" }
105
- how_to_get_cookies = cgi.a(Tap::Http::Utils::COOKIES_HELP_URL) { "how to get cookies" }
106
-
107
- cgi.out do
108
- cgi.html do
109
- cgi.body do
110
- cgi.pre do %Q{
111
- # Copy and paste into a configuration file. Multiple configs
112
- # can be added to a single file to perform batch submission.
113
- #
114
- # If you need cookies, see #{how_to_get_cookies} or the #{help}.
115
- - #{config.to_yaml[5..-1].gsub(/\n/, "\n ")}
116
- }
117
- end
118
- end
119
- end
120
- end
121
-
122
- end
123
-
124
- rescue
125
- cgi.out("text/plain") do
126
- "Error: #{$!.message}\n" +
127
- $!.backtrace.join("\n")
128
- end
129
- end