123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::HostAuthorization::DefaultResponseApp

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/middleware/host_authorization.rb

Constant Summary

Instance Method Summary

Instance Method Details

#available_logger(request) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/host_authorization.rb', line 122

def available_logger(request)
  request.logger || ActionView::Base.logger
end

#call(env)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/host_authorization.rb', line 91

def call(env)
  request = Request.new(env)
  format = request.xhr? ? "text/plain" : "text/html"

  log_error(request)
  response(format, response_body(request))
end

#log_error(request) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/host_authorization.rb', line 114

def log_error(request)
  logger = available_logger(request)

  return unless logger

  logger.error("[#{self.class.name}] Blocked hosts: #{request.env["action_dispatch.blocked_hosts"].join(", ")}")
end

#response(format, body) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/host_authorization.rb', line 107

def response(format, body)
  [RESPONSE_STATUS,
   { Rack::CONTENT_TYPE => "#{format}; charset=#{Response.default_charset}",
     Rack::CONTENT_LENGTH => body.bytesize.to_s },
   [body]]
end

#response_body(request) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/host_authorization.rb', line 100

def response_body(request)
  return "" unless request.get_header("action_dispatch.show_detailed_exceptions")

  template = DebugView.new(hosts: request.env["action_dispatch.blocked_hosts"])
  template.render(template: "rescues/blocked_host", layout: "rescues/layout")
end