Class: Castle::Extractors::IP
- Inherits:
-
Object
- Object
- Castle::Extractors::IP
- Defined in:
- lib/castle/extractors/ip.rb
Overview
used for extraction of ip from the request
Constant Summary collapse
- DEPTH_RELATED =
list of header which are used with proxy depth setting
%w[X-Forwarded-For].freeze
Instance Method Summary collapse
-
#call ⇒ String
Order of headers: .…
-
#initialize(headers) ⇒ IP
constructor
A new instance of IP.
Constructor Details
#initialize(headers) ⇒ IP
Returns a new instance of IP.
15 16 17 18 19 20 21 |
# File 'lib/castle/extractors/ip.rb', line 15 def initialize(headers) @headers = headers @ip_headers = Castle.config.ip_headers.empty? ? DEFAULT : Castle.config.ip_headers @proxies = Castle.config.trusted_proxies + Castle::Configuration::TRUSTED_PROXIES @trust_proxy_chain = Castle.config.trust_proxy_chain @trusted_proxy_depth = Castle.config.trusted_proxy_depth end |
Instance Method Details
#call ⇒ String
Order of headers:
.... list of headers defined by ip_headers
X-Forwarded-For
Remote-Addr
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/castle/extractors/ip.rb', line 28 def call all_ips = [] @ip_headers.each do |ip_header| ips = ips_from(ip_header) ip_value = remove_proxies(ips) return ip_value if ip_value all_ips.push(*ips) end # fallback to first listed ip all_ips.first end |