class ActionDispatch::Routing::Redirect
:nodoc:
def call(env)
def call(env) req = Request.new(env) # If any of the path parameters has a invalid encoding then # raise since it's likely to trigger errors further on. req.symbolized_path_parameters.each do |key, value| unless value.valid_encoding? raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}" end end uri = URI.parse(path(req.symbolized_path_parameters, req)) uri.scheme ||= req.scheme uri.host ||= req.host uri.port ||= req.port unless req.standard_port? if relative_path?(uri.path) uri.path = "#{req.script_name}/#{uri.path}" end body = %(<html><body>You are being <a href="#{ERB::Util.h(uri.to_s)}">redirected</a>.</body></html>) headers = { 'Location' => uri.to_s, 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s } [ status, headers, [body] ] end
def initialize(status, block)
def initialize(status, block) @status = status @block = block end
def inspect
def inspect "redirect(#{status})" end
def path(params, request)
def path(params, request) block.call params, request end
def relative_path?(path)
def relative_path?(path) path && !path.empty? && path[0] != '/' end