Class: Middleware::CloudflareGeoSimulator
- Inherits:
-
Object
- Object
- Middleware::CloudflareGeoSimulator
- Defined in:
- lib/middleware/cloudflare_geo_simulator.rb
Constant Summary collapse
- DEFAULT_PROFILE =
Default profile when TRACK_VISITOR=y but no TRACK_VISITOR_PROFILE specified
'US-IL'- PROFILES =
{ # United States - Various states (Opt-out model) # Format: US-XX where XX is the state code 'US-IL' => { country: 'US', region: 'Illinois', region_code: 'IL', city: 'Lake Zurich', postal_code: '60047', latitude: '42.1969', longitude: '-88.0934', timezone: 'America/Chicago', simulated_ip: '69.171.224.1' # Illinois IP }, 'US-CA' => { country: 'US', region: 'California', region_code: 'CA', city: 'San Francisco', postal_code: '94102', latitude: '37.7749', longitude: '-122.4194', timezone: 'America/Los_Angeles', simulated_ip: '8.8.8.8' # Google DNS (California) }, 'US-TX' => { country: 'US', region: 'Texas', region_code: 'TX', city: 'Austin', postal_code: '78701', latitude: '30.2672', longitude: '-97.7431', timezone: 'America/Chicago', simulated_ip: '104.215.148.63' # Azure Texas }, 'US-NY' => { country: 'US', region: 'New York', region_code: 'NY', city: 'New York', postal_code: '10001', latitude: '40.7128', longitude: '-74.0060', timezone: 'America/New_York', simulated_ip: '74.125.224.72' # Google NYC }, 'US-FL' => { country: 'US', region: 'Florida', region_code: 'FL', city: 'Miami', postal_code: '33101', latitude: '25.7617', longitude: '-80.1918', timezone: 'America/New_York', simulated_ip: '65.190.0.1' # Florida IP }, # Canada - Quebec (Law 25 - Opt-in required) 'CA-QC' => { country: 'CA', region: 'Quebec', region_code: 'QC', city: 'Montreal', postal_code: 'H2X 1Y4', latitude: '45.5017', longitude: '-73.5673', timezone: 'America/Toronto', simulated_ip: '132.204.24.179' # McGill University Montreal }, # Canada - Other provinces (Implied consent) 'CA-ON' => { country: 'CA', region: 'Ontario', region_code: 'ON', city: 'Toronto', postal_code: 'M5V 1J2', latitude: '43.6532', longitude: '-79.3832', timezone: 'America/Toronto', simulated_ip: '99.79.0.1' # AWS Canada }, 'CA-AB' => { country: 'CA', region: 'Alberta', region_code: 'AB', city: 'Calgary', postal_code: 'T2P 1J9', latitude: '51.0447', longitude: '-114.0719', timezone: 'America/Edmonton', simulated_ip: '136.159.2.1' # University of Calgary }, 'CA-BC' => { country: 'CA', region: 'British Columbia', region_code: 'BC', city: 'Vancouver', postal_code: 'V6B 1A1', latitude: '49.2827', longitude: '-123.1207', timezone: 'America/Vancouver', simulated_ip: '142.103.1.1' # UBC Vancouver }, # European Union - GDPR (Opt-in required) 'DE' => { country: 'DE', region: 'Bavaria', region_code: 'BY', city: 'Munich', postal_code: '80331', latitude: '48.1351', longitude: '11.5820', timezone: 'Europe/Berlin', simulated_ip: '185.220.101.1' # German IP }, 'FR' => { country: 'FR', region: 'Île-de-France', region_code: 'IDF', city: 'Paris', postal_code: '75001', latitude: '48.8566', longitude: '2.3522', timezone: 'Europe/Paris', simulated_ip: '90.63.1.1' # Orange France }, 'ES' => { country: 'ES', region: 'Community of Madrid', region_code: 'MD', city: 'Madrid', postal_code: '28001', latitude: '40.4168', longitude: '-3.7038', timezone: 'Europe/Madrid', simulated_ip: '88.27.1.1' # Telefonica Spain }, 'IT' => { country: 'IT', region: 'Lazio', region_code: 'RM', city: 'Rome', postal_code: '00100', latitude: '41.9028', longitude: '12.4964', timezone: 'Europe/Rome', simulated_ip: '151.15.1.1' # Telecom Italia }, 'NL' => { country: 'NL', region: 'North Holland', region_code: 'NH', city: 'Amsterdam', postal_code: '1012', latitude: '52.3676', longitude: '4.9041', timezone: 'Europe/Amsterdam', simulated_ip: '145.97.1.1' # Dutch IP }, # United Kingdom - UK GDPR (Opt-in required) 'GB' => { country: 'GB', region: 'England', region_code: 'ENG', city: 'London', postal_code: 'EC1A 1BB', latitude: '51.5074', longitude: '-0.1278', timezone: 'Europe/London', simulated_ip: '81.2.69.142' # UK IP }, # Switzerland - nFADP (Opt-in required) 'CH' => { country: 'CH', region: 'Zurich', region_code: 'ZH', city: 'Zurich', postal_code: '8001', latitude: '47.3769', longitude: '8.5417', timezone: 'Europe/Zurich', simulated_ip: '178.197.1.1' # Swisscom }, # Other regions 'BR' => { country: 'BR', region: 'São Paulo', region_code: 'SP', city: 'São Paulo', postal_code: '01310-100', latitude: '-23.5505', longitude: '-46.6333', timezone: 'America/Sao_Paulo', simulated_ip: '177.71.1.1' # Brazil IP }, 'AU' => { country: 'AU', region: 'New South Wales', region_code: 'NSW', city: 'Sydney', postal_code: '2000', latitude: '-33.8688', longitude: '151.2093', timezone: 'Australia/Sydney', simulated_ip: '1.128.1.1' # Telstra Australia }, 'JP' => { country: 'JP', region: 'Tokyo', region_code: '13', city: 'Tokyo', postal_code: '100-0001', latitude: '35.6762', longitude: '139.6503', timezone: 'Asia/Tokyo', simulated_ip: '126.1.1.1' # SoftBank Japan }, 'MX' => { country: 'MX', region: 'Mexico City', region_code: 'CMX', city: 'Mexico City', postal_code: '06600', latitude: '19.4326', longitude: '-99.1332', timezone: 'America/Mexico_City', simulated_ip: '189.203.1.1' # Telmex Mexico }, # Unknown/Test scenarios 'UNKNOWN' => { country: 'XX', # Cloudflare uses XX for unknown region: nil, region_code: nil, city: nil, postal_code: nil, latitude: nil, longitude: nil, timezone: nil, simulated_ip: '192.0.2.1' # TEST-NET-1 (documentation IP) }, 'NONE' => { # No headers at all - tests fallback to geocoder worker simulated_ip: '198.51.100.1' # TEST-NET-2 } }.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ CloudflareGeoSimulator
constructor
A new instance of CloudflareGeoSimulator.
Constructor Details
#initialize(app) ⇒ CloudflareGeoSimulator
Returns a new instance of CloudflareGeoSimulator.
301 302 303 |
# File 'lib/middleware/cloudflare_geo_simulator.rb', line 301 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
305 306 307 308 309 310 |
# File 'lib/middleware/cloudflare_geo_simulator.rb', line 305 def call(env) # Only active in development with TRACK_VISITOR=y and only for www subdomain inject_cloudflare_headers(env) if Rails.env.development? && ENV['TRACK_VISITOR'].to_s.downcase == 'y' && www_subdomain?(env) @app.call(env) end |