lib/grover/middleware.rb in grover-0.2.1 vs lib/grover/middleware.rb in grover-0.2.2
- old
+ new
@@ -17,12 +17,13 @@
configure_env_for_pdf_request(env) if render_as_pdf?
status, headers, response = @app.call(env)
if rendering_pdf? && html_content?(headers)
- response = convert_to_pdf response
- update_headers headers, body
+ pdf = convert_to_pdf response
+ response = [pdf]
+ update_headers headers, pdf
end
[status, headers, response]
end
@@ -43,12 +44,11 @@
def convert_to_pdf(response)
body = response.respond_to?(:body) ? response.body : response.join
body = body.join if body.is_a?(Array)
body = HTMLPreprocessor.process body, request_url, protocol
- body = Grover.new(body).to_pdf
- [body]
+ Grover.new(body).to_pdf
end
def update_headers(headers, body)
# Do not cache PDFs
headers.delete 'ETag'
@@ -77,8 +77,12 @@
"#{env['rack.url_scheme']}://#{env['HTTP_HOST']}/"
end
def protocol
env['rack.url_scheme']
+ end
+
+ def env
+ @request.env
end
end
end