Class: SimpleCaptchaReloaded::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_captcha_reloaded/middleware.rb

Constant Summary collapse

DEFAULT_SEND_FILE_OPTIONS =
{
  :type         => 'application/octet-stream'.freeze,
  :disposition  => 'attachment'.freeze,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
# File 'lib/simple_captcha_reloaded/middleware.rb', line 7

def initialize(app, options={})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simple_captcha_reloaded/middleware.rb', line 11

def call(env)
  @env = env
  if env["REQUEST_METHOD"] == "GET" && captcha_path?(env['PATH_INFO'])
    if request.params.present? && (code = request.params['code']) && code.present?
      make_image(code)
    else
      refresh_code
    end
  else
    @app.call(env)
  end
end