lib/seo_cache/middleware.rb in seo_cache-1.0.2 vs lib/seo_cache/middleware.rb in seo_cache-1.0.3
- old
+ new
@@ -35,21 +35,21 @@
end
else
Thread.new do
prerender_data = page_render(env)
# Extract status from render page or return 404
- status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first || 404
+ status = prerender_data&.scan(/<!--status:(\d+)-->/)&.last&.first
after_render(env, prerender_data, status || 200)
end
end
elsif prerender_params?(env)
env['seo_mode'] = true
# Add status to render page because Selenium doesn't return http headers or status...
status, headers, response = @app.call(env)
status_code = "<!--status:#{status}-->"
# Cannot add at the top of file, Chrome removes leading comments...
begin
- body_code = response.body.sub('<head>', "<head>#{status_code}")
+ body_code = response.body.sub(/<head( ?)(.*?)>/i, "<head\\1\\2>#{status_code}")
return [status, headers, [body_code]]
rescue
return [status, headers, [nil]]
end
end