lib/simple_captcha/middleware.rb in simple_captcha2-0.3.2 vs lib/simple_captcha/middleware.rb in simple_captcha2-0.3.3

- old
+ new

@@ -37,11 +37,11 @@ #status, headers, body = @app.call(env) #status = 200 #body = generate_simple_captcha_image(code) #headers['Content-Type'] = 'image/jpeg' - send_file(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg') + send_data(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg') else [status, headers, body] end end @@ -57,9 +57,16 @@ 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") [status, headers, response_body] + end + + def send_data(response_body, options = {}) + status = options[:status] || 200 + headers = {"Content-Disposition" => "#{options[:disposition]}; filename='#{options[:filename]}'", "Content-Type" => options[:type], 'Content-Transfer-Encoding' => 'binary', 'Cache-Control' => 'private'} + + [status, headers, [response_body]] end def refresh_code(env) request = Rack::Request.new(env)