mikehale-rat-hole 0.1.8 → 0.1.9
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.
- data/CHANGELOG.rdoc +4 -0
- data/VERSION.yml +1 -1
- data/lib/rat_hole.rb +6 -4
- data/test/test_rat_hole.rb +15 -2
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
data/VERSION.yml
CHANGED
data/lib/rat_hole.rb
CHANGED
@@ -44,11 +44,12 @@ class RatHole
|
|
44
44
|
code = response.code.to_i
|
45
45
|
headers = response.to_hash
|
46
46
|
body = response.body || ''
|
47
|
-
body = tidy_html(body) if @tidy
|
48
47
|
headers.delete('Transfer-Encoding')
|
49
48
|
|
50
49
|
server_response = Rack::Response.new(body, code, headers)
|
51
50
|
whack_array(server_response)
|
51
|
+
tidy_html(body) if server_response["Content-Type"] =~ /text\/html/ && @tidy
|
52
|
+
|
52
53
|
process_server_response(server_response, source_request)
|
53
54
|
server_response.finish
|
54
55
|
end
|
@@ -67,12 +68,13 @@ class RatHole
|
|
67
68
|
$stderr.puts "tidy not found in path"
|
68
69
|
return
|
69
70
|
end
|
70
|
-
tidied = Open3.popen3('tidy -ascii') do |stdin, stdout, stderr|
|
71
|
+
tidied, errors = Open3.popen3('tidy -ascii') do |stdin, stdout, stderr|
|
71
72
|
stdin.print body
|
72
73
|
stdin.close
|
73
|
-
stdout.read
|
74
|
+
[stdout.read, stderr.read]
|
74
75
|
end
|
75
|
-
|
76
|
+
$stderr.puts errors if $DEBUG
|
77
|
+
body.replace(tidied) if tidied != ""
|
76
78
|
end
|
77
79
|
|
78
80
|
def request_headers(env)
|
data/test/test_rat_hole.rb
CHANGED
@@ -53,9 +53,9 @@ class TestRatHole < Test::Unit::TestCase
|
|
53
53
|
MockRequest.new(@io.written)
|
54
54
|
end
|
55
55
|
|
56
|
-
def send_get_request(rack_env={}, uri='/someuri')
|
56
|
+
def send_get_request(rack_env={}, uri='/someuri', tidy=false)
|
57
57
|
opts = {:lint=>true}.merge(rack_env)
|
58
|
-
rh = RatHole.new('127.0.0.1')
|
58
|
+
rh = RatHole.new('127.0.0.1', tidy)
|
59
59
|
Rack::MockRequest.new(rh).get(uri, opts)
|
60
60
|
end
|
61
61
|
|
@@ -182,6 +182,19 @@ class TestRatHole < Test::Unit::TestCase
|
|
182
182
|
send_post_request('', '/uri?with=param')
|
183
183
|
assert_equal('/uri?with=param', proxied_request.uri)
|
184
184
|
end
|
185
|
+
|
186
|
+
def test_tidy_fails
|
187
|
+
body = '<something tidy <will </barf on'
|
188
|
+
mock_server(:body => body)
|
189
|
+
response = send_get_request({}, '/', true)
|
190
|
+
assert_equal(response.body, body)
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_tidy_tidies
|
194
|
+
mock_server(:body => 'tidy me')
|
195
|
+
response = send_get_request({:lint=>false}, '/', true)
|
196
|
+
assert response.body =~ /html/i
|
197
|
+
end
|
185
198
|
end
|
186
199
|
|
187
200
|
class TestEmptyRatHole < RatHoleTest
|