lib/simple_captcha/middleware.rb in glebtv-simple_captcha-0.2.1 vs lib/simple_captcha/middleware.rb in glebtv-simple_captcha-0.3.1

- old
+ new

@@ -24,12 +24,18 @@ protected def make_image(env, headers = {}, status = 404) request = Rack::Request.new(env) code = request.params["code"] body = [] + if !code.blank? && Utils::simple_captcha_value(code) - return send_file(generate_simple_captcha_image(code), :type => 'image/png', :disposition => 'inline', :filename => 'simple_captcha.png') + #status, headers, body = @app.call(env) + #status = 200 + #body = generate_simple_captcha_image(code) + #headers['Content-Type'] = 'image/jpeg' + + return send_file(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg') end [status, headers, body] end @@ -42,11 +48,11 @@ options[:filename] ||= File.basename(path) unless options[:url_based_filename] status = options[:status] || 200 headers = {"Content-Disposition" => "#{options[:disposition]}; filename='#{options[:filename]}'", "Content-Type" => options[:type], 'Content-Transfer-Encoding' => 'binary', 'Cache-Control' => 'private'} - response_body = File.open(path, 'rb').read - File.unlink(path) - [status, headers, [response_body]] + response_body = File.open(path, "rb") + + [status, headers, response_body] end end end