lib/pdfkit/middleware.rb in pdfkit-0.3.3 vs lib/pdfkit/middleware.rb in pdfkit-0.4.0

- old
+ new

@@ -42,17 +42,18 @@ def translate_paths(body, env) # Host with protocol root = env['rack.url_scheme'] + "://" + env['HTTP_HOST'] + "/" body.gsub!(/(href|src)=['"]\/([^\"']*|[^"']*)['"]/,'\1="'+root+'\2"') + + return body end def set_request_to_render_as_pdf(env) @render_pdf = true - puts "Setting PDF mode" - + path = Pathname(env['PATH_INFO']) - env['PATH_INFO'] = path.to_s.sub(/#{path.extname}$/,'') if path.extname == '.pdf' + ['PATH_INFO','REQUEST_URI'].each { |e| env[e] = path.to_s.sub(/#{path.extname}$/,'') } if path.extname == '.pdf' env['HTTP_ACCEPT'] = concat(env['HTTP_ACCEPT'], Rack::Mime.mime_type('.html')) end def concat(accepts, type) (accepts || '').split(',').unshift(type).compact.join(',')