Class: Castle::IPs::Extract
- Inherits:
-
Object
- Object
- Castle::IPs::Extract
- Defined in:
- lib/castle/ips/extract.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, config = nil) ⇒ Extract
constructor
A new instance of Extract.
Constructor Details
#initialize(headers, config = nil) ⇒ Extract
Returns a new instance of Extract.
18 19 20 21 22 23 24 25 |
# File 'lib/castle/ips/extract.rb', line 18 def initialize(headers, config = nil) config ||= Castle.config @headers = headers @ip_headers = config.ip_headers.empty? ? DEFAULT : config.ip_headers @proxies = config.trusted_proxies + Castle::Configuration::TRUSTED_PROXIES @trust_proxy_chain = config.trust_proxy_chain @trusted_proxy_depth = 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/castle/ips/extract.rb', line 32 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 |