class RailsMiniProfiler::Redirect

Renders a redirect response if the user should be redirected from the original request

Public Class Methods

new(request_context) click to toggle source

@param request_context [RequestContext] the current request context

# File lib/rails_mini_profiler/redirect.rb, line 9
def initialize(request_context)
  @request = request_context.request
  @profiled_request = request_context.profiled_request
end

Public Instance Methods

render() click to toggle source

Renders a redirect to a specific resource under certain conditions

When the user requests a Flamegraph using a parameter for a specific request, they are being served a redirect.

@return [Boolean] false if no redirect happens @return [Array] response with status 302 and the new location to redirect to

# File lib/rails_mini_profiler/redirect.rb, line 20
def render
  params = CGI.parse(@request.query_string).transform_values(&:first).with_indifferent_access
  return redirect_to(flamegraph_path(@profiled_request.id)) if params[:rmp_flamegraph].present?

  false
end

Private Instance Methods

redirect_to(location) click to toggle source
# File lib/rails_mini_profiler/redirect.rb, line 29
def redirect_to(location)
  [302, { 'Location' => location, 'Content-Type' => 'text/html' }, ['Moved Temporarily']]
end