Class: WebConsole::Request

Inherits:
ActionDispatch::Request
  • Object
show all
Defined in:
lib/web_console/request.rb

Overview

Web Console tailored request object.

Defined Under Namespace

Classes: GetSecureIp

Constant Summary collapse

@@acceptable_content_types =
[Mime::HTML, Mime::TEXT, Mime::URL_ENCODED_FORM]
@@whitelisted_ips =
Whitelist.new

Instance Method Summary collapse

Instance Method Details

#acceptable_content_type?Boolean

Returns whether the request is from an acceptable content type.

We can render a console for HTML and TEXT by default. If a client didn’t specified any content type and the server returned it as blank, we’ll render it as well.



31
32
33
# File 'lib/web_console/request.rb', line 31

def acceptable_content_type?
  content_type.blank? || content_type.in?(acceptable_content_types)
end

#from_whitelited_ip?Boolean

Returns whether a request came from a whitelisted IP.

For a request to hit Web Console features, it needs to come from a white listed IP.



17
18
19
# File 'lib/web_console/request.rb', line 17

def from_whitelited_ip?
  whitelisted_ips.include?(strict_remote_ip)
end

#strict_remote_ipObject

Determines the remote IP using our much stricter whitelist.



22
23
24
# File 'lib/web_console/request.rb', line 22

def strict_remote_ip
  GetSecureIp.new(env, whitelisted_ips).to_s
end