The default worker request headers have
cf-ipcountry which gives me the country code of the visitor. There’s also
cf-connecting-ip which gives me their IP.
But can I get more detailed information like region, city or lat / lon?
Otherwise, I’d have to make another API call to get more detailed info from the IP address, which would significantly up the latency.
Other than the Country header, there’s really nothing. There might be some documentation that infers that there’s more localized information from Cloudflare. If it ever really existed, it’s been deprecated.
EDIT: Awesome! @eva2000 found the docs I couldn’t locate.
Looks like Fastly lets you access precise location data via VCL:
And Cloudflare seems to almost be getting there:
Would be very useful if these fields were accessible from the worker too.
That looks like the same country code as the header method.
Yeah! I just meant it would be very useful if Cloudflare had the fields that the Fastly page lists, and exposed them to workers.
cf request object has some https://developers.cloudflare.com/workers/reference/apis/request/
In addition to the properties on the standard
Request object, you can use a
request.cf object to control how Cloudflare features are applied as well as other custom information provided by Cloudflare.
Note: Currently, settings in the cf object cannot be tested in the playground.
Special information from an incoming request to help with your app’s logic. All plans have access to:
asn : ASN of the incoming request. (e.g.
colo : The three-letter airport code of the data center that the request hit. (e.g.
weight: The browser-requested weight for the HTTP/2 prioritization.
exclusive: The browser-requested HTTP/2 exclusive flag (1 for Chromium-based browsers, 0 for others).
group: HTTP/2 stream ID for the request group (only non-zero for Firefox).
group-weight : HTTP/2 weight for the request group (only non-zero for Firefox).
tlsCipher : The cipher for the connection to Cloudflare. (e.g.
country : Country of the incoming request. The two-letter country code in the request. This is the same value as that provided in the
CF-IPCountry header. (e.g.
tlsClientAuth : Only set when using Cloudflare Access. Object with the following properties:
tlsVersion : The TLS version of the connection to Cloudflare (e.g.
Business and Enterprise scripts have access to:
requestPriority : The browser-requested prioritization information in the request object. (e.g.
city : City of the incoming request. (e.g.
continent : Continent of the incoming request. (e.g.
httpProtocol : HTTP Protocol (e.g.
latitude : Latitude of the incoming request. (e.g.
longitude : Longitude of the incoming request. (e.g.
postalCode : PostalCode of the incoming request. (e.g.
region : If known, the ISO 3166-2 name for the first level region associated with the IP address of the incoming request. If not known, this is an empty string. (e.g.
regionCode : If known, the ISO 3166-2 code for the first level region associated with the IP address of the incoming request. 1 If not known, this is an empty string. (e.g.
timezone : Timezone of the incoming request. (e.g.
Great, this is what I was looking for, thank you!