DEV Community

BC
BC

Posted on

Get country code from request proxied by Cloudflare

If your web server is proxied via cloudflare, you can get request's country code:

Python Flask

country_code = request.headers.get('cf-ipcountry')
Enter fullscreen mode Exit fullscreen mode

Golang Fiber

countryCode := c.Get("cf-ipcountry")
Enter fullscreen mode Exit fullscreen mode

Print out examples:

  • US (united states)
  • JP (Japan)
  • NL (Netherland)

Reference

Top comments (0)