class Shield::Middleware

Attributes

url[R]

Public Class Methods

new(app, url = "/login") click to toggle source
# File lib/shield.rb, line 8
def initialize(app, url = "/login")
  @app = app
  @url = url
end

Public Instance Methods

call(env) click to toggle source
# File lib/shield.rb, line 13
def call(env)
  tuple = @app.call(env)

  if tuple[0] == 401
    [302, headers(env["SCRIPT_NAME"] + env["PATH_INFO"]), []]
  else
    tuple
  end
end

Private Instance Methods

encode(str) click to toggle source
# File lib/shield.rb, line 31
def encode(str)
  URI.encode_www_form_component(str)
end
headers(path) click to toggle source
# File lib/shield.rb, line 24
def headers(path)
  { "Location" => "%s?return=%s" % [url, encode(path)],
    "Content-Type" => "text/html",
    "Content-Length" => "0"
  }
end