rack-noindex_https 0.0.1 → 0.0.2
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/lib/rack-noindex_https/version.rb +1 -1
- data/lib/rack-noindex_https.rb +1 -1
- data/spec/no_index_https_spec.rb +4 -0
- data/spec/spec_helper.rb +3 -1
- metadata +1 -1
data/lib/rack-noindex_https.rb
CHANGED
@@ -14,7 +14,7 @@ module Rack
|
|
14
14
|
@status, @headers, @body = @app.call(env)
|
15
15
|
request = Rack::Request.new(env)
|
16
16
|
|
17
|
-
if request.scheme == 'https' && @headers['Content-Type']
|
17
|
+
if request.scheme == 'https' && (@headers['Content-Type'] =~ /application\/html/ || @headers['Content-Type'] =~ /text\/html/)
|
18
18
|
@body = @body.collect {|fragement| fragement.gsub(%r{</head>}, '<meta name="robots" content="noindex"></head>') }
|
19
19
|
end
|
20
20
|
|
data/spec/no_index_https_spec.rb
CHANGED
@@ -7,6 +7,10 @@ module Rack
|
|
7
7
|
get('https://example.org/').body.should == '<html><head>Hello world<meta name="robots" content="noindex"></head><body></body></html>'
|
8
8
|
end
|
9
9
|
|
10
|
+
it 'should inject no index tag into head of https HTML request for text/html' do
|
11
|
+
get('https://example.org/text.html').body.should == '<html><head>Hello world<meta name="robots" content="noindex"></head><body></body></html>'
|
12
|
+
end
|
13
|
+
|
10
14
|
it 'should not inject no index tag of http HTML request' do
|
11
15
|
get('/').body.should == '<html><head>Hello world</head><body></body></html>'
|
12
16
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,9 @@ def main_app
|
|
10
10
|
request = Rack::Request.new(env)
|
11
11
|
case request.path
|
12
12
|
when '/' then
|
13
|
-
[200, {'Content-Type' => 'application/html'}, ['<html><head>Hello world</head><body></body></html>']]
|
13
|
+
[200, {'Content-Type' => 'application/html; charset=utf-8'}, ['<html><head>Hello world</head><body></body></html>']]
|
14
|
+
when '/text.html' then
|
15
|
+
[200, {'Content-Type' => ' text/html; charset=utf-8'}, ['<html><head>Hello world</head><body></body></html>']]
|
14
16
|
when '/test.xml' then
|
15
17
|
[200, {'Content-Type' => 'application/xml'}, ['<head></head><xml></xml>']]
|
16
18
|
when '/bob' then
|