Github iconEdit on Github
This version of the Cloudflare Workers documentation is deprecated. Visit the new documentation

Inspecting Visitor Location

Workers can tell you about a visitor through a couple custom headers.

Obtaining a visitor's country code:

With VCL:

set req.http.CDN-GeoIP-CountryCode = client.geo.country_code;

With Workers:

const countryCode = request.headers.get("cf-ipcountry")

Obtaining a visitor's ip address:

With Workers:

const ip = request.headers.get("cf-connecting-ip")