Class: ActionDispatch::Routing::Redirect
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Endpoint
|
|
|
Instance Chain:
self,
Endpoint
|
|
| Inherits: |
ActionDispatch::Routing::Endpoint
|
| Defined in: | actionpack/lib/action_dispatch/routing/redirection.rb |
Class Method Summary
- .new(status, block, source_location) ⇒ Redirect constructor
Instance Attribute Summary
- #block (also: #options) readonly
- #redirect? ⇒ Boolean readonly
- #status readonly
Endpoint - Inherited
Instance Method Summary
- #build_response(req)
- #call(env)
- #inspect
- #path(params, request)
- #escape(params) private
- #escape_fragment(params) private
- #escape_path(params) private
- #relative_path?(path) ⇒ Boolean private
Endpoint - Inherited
Constructor Details
.new(status, block, source_location) ⇒ Redirect
Instance Attribute Details
#block (readonly) Also known as: #options
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 13
attr_reader :status, :block
#redirect? ⇒ Boolean (readonly)
[ GitHub ]
# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 21
def redirect?; true; end
#status (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 13
attr_reader :status, :block
Instance Method Details
#build_response(req)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 37
def build_response(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 = "" headers = { "Location" => uri.to_s, "Content-Type" => "text/html; charset=#{ActionDispatch::Response.default_charset}", "Content-Length" => body.length.to_s } ActionDispatch::Response.new(status, headers, body) end
#call(env)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 23
def call(env) ActiveSupport::Notifications.instrument("redirect.action_dispatch") do |payload| request = Request.new(env) response = build_response(request) payload[:status] = @status payload[:location] = response.headers["Location"] payload[:request] = request payload[:source_location] = @source_location if @source_location response.to_a end end
#escape(params) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 78
def escape(params) params.transform_values { |v| Rack::Utils.escape(v) } end
#escape_fragment(params) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 82
def escape_fragment(params) params.transform_values { |v| Journey::Router::Utils.escape_fragment(v) } end
#escape_path(params) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 86
def escape_path(params) params.transform_values { |v| Journey::Router::Utils.escape_path(v) } end
#inspect
[ GitHub ]# File 'actionpack/lib/action_dispatch/routing/redirection.rb', line 69
def inspect "redirect(#{status})" end