Module: Rack::Cloudflare::IPs
- Defined in:
- lib/rack/cloudflare/ips.rb
Constant Summary collapse
- V4_URL =
See: www.cloudflare.com/ips/
'https://www.cloudflare.com/ips-v4'
- V6_URL =
'https://www.cloudflare.com/ips-v6'
- V4 =
read("#{__dir__}/../../../data/ips_v4.txt")
- V6 =
read("#{__dir__}/../../../data/ips_v6.txt")
- DEFAULTS =
V4 + V6
Class Attribute Summary collapse
-
.list ⇒ Object
List of IPs to reference.
Class Method Summary collapse
- .fetch(url) ⇒ Object
- .parse(string) ⇒ Object
- .read(filename) ⇒ Object
-
.refresh! ⇒ Object
Refresh list of IPs in case local copy is outdated.
Class Attribute Details
.list ⇒ Object
List of IPs to reference
15 16 17 |
# File 'lib/rack/cloudflare/ips.rb', line 15 def list @list end |
Class Method Details
.fetch(url) ⇒ Object
22 23 24 |
# File 'lib/rack/cloudflare/ips.rb', line 22 def fetch(url) parse ::Net::HTTP.get(URI(url)) end |
.parse(string) ⇒ Object
30 31 32 33 |
# File 'lib/rack/cloudflare/ips.rb', line 30 def parse(string) return [] if string.to_s.strip.empty? string.split(/[,\s]+/).map { |ip| ::IPAddr.new(ip.strip) } end |
.read(filename) ⇒ Object
26 27 28 |
# File 'lib/rack/cloudflare/ips.rb', line 26 def read(filename) parse ::File.read(filename) end |