feat: stash CF-RegionCode and CF-IPCity headers in g for future use

All three Cloudflare geo headers now available:
- g.user_country (CF-IPCountry) — used by geo-sorted article listing
- g.user_region (CF-RegionCode) — available for within-country sorting
- g.user_city (CF-IPCity) — available for city-level proximity

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-03-08 20:26:50 +01:00
parent d7bd053dc6
commit 40d8c75b81

View File

@@ -149,9 +149,16 @@ def create_app() -> Quart:
# -------------------------------------------------------------------------
@app.before_request
async def set_user_country():
"""Stash Cloudflare CF-IPCountry header (ISO alpha-2) in g for geo sorting."""
async def set_user_geo():
"""Stash Cloudflare geo headers in g for proximity sorting.
Requires nginx: proxy_set_header CF-IPCountry $http_cf_ipcountry;
proxy_set_header CF-RegionCode $http_cf_regioncode;
proxy_set_header CF-IPCity $http_cf_ipcity;
"""
g.user_country = request.headers.get("CF-IPCountry", "").upper() or ""
g.user_region = request.headers.get("CF-RegionCode", "") or ""
g.user_city = request.headers.get("CF-IPCity", "") or ""
@app.before_request
async def validate_lang():