# frozen_string_literal: true require "active_support/core_ext/array/extract_options" require "rack/utils" require "action_controller/metal/exceptions" require "action_dispatch/routing/endpoint" module ActionDispatch module Routing class Redirect < Endpoint # :nodoc: attr_reader :status, :block def initialize(status, block) @status = status @block = block end def redirect?; true; end def call(env) serve Request.new env end def serve(req) uri = URI.parse(path(req.path_parameters, req)) unless uri.host if relative_path?(uri.path) uri.path = "#{req.script_name}/#{uri.path}" elsif uri.path.empty? uri.path = req.script_name.empty? ? "/" : req.script_name end end uri.scheme ||= req.scheme uri.host ||= req.host uri.port ||= req.port unless req.standard_port? req.commit_flash body = %(
You are being redirected.