Geo IP feature for country and state

I find the cf-ipcountry feature quite nice, and quite accurate.
It even detected one Cogent IP being in Germany!
But wouldn’t it be great if for US addresses I could get the state as well?
The US is big. Would really like to know the state …
Something like cf-ipstate maybe? :grinning:

It’s already available in the Workers’ request object. Not totally sure what is available at what plan level.

1 Like

Wouldn’t it be inefficient to proxy my entire website (terabytes of data) thru a Worker just to add this one piece of information?

All I want is for CF to add a HTTP header with regionCode information to my request…

No. As @KentonVarda would say the Worker latency increase is ~1ms at most unless you have processor intensive tasks.

I would expect them to do that via a Worker regardless even if not exposed to you directly. Move some additional logic there, the users will benefit it.

Also, if you have terabytes of data flowing through you may be interested in an ENT plan. Contact sales, in there you get custom features.

Looks like the regionCode field in CF isn’t being populated.
In fact, no region information is set at all.

Example CF object (my provider is Comcast):

{
    "tlsExportedAuthenticator": ...,
    "tlsVersion": "TLSv1.3",
    "httpProtocol": "HTTP/2",
    "tlsCipher": "AEAD-AES128-GCM-SHA256",
    "edgeRequestKeepAliveStatus": 1,
    "requestPriority": "weight=42;exclusive=0;group=13;group-weight=241",
    "country": "US",
    "clientAcceptEncoding": "gzip, deflate, br",
    "clientTcpRtt": 40,
    "colo": "ORD",
    "tlsClientAuth": ...,
    "asn": 7922
}

My Worker code:

addEventListener('fetch', event => {
  var req = event.request;
  var hdrs = new Headers(req.headers);
  if (req.cf && req.cf.regionCode)
    hdrs.append("CF-RegionCode", req.cf.regionCode);
  if (req.cf && req.cf.asn)
    hdrs.append("CF-ASN", req.cf.asn);
  hdrs.append("CF", JSON.stringify(req.cf, null, 0)); // temporary, for debugging only
  req = new Request(req.url, {
    body: req.body,
    headers: hdrs,
    method: req.method,
    redirect: req.redirect
  })
  event.respondWith(fetch(req))
})

Tried from 3 different US IPs, same result…

Any idea what I’m doing wrong?

What plan level are you on? I believe it requires Business and up.

Oh that could explain it. We do have Business, but not on all domains. This feature was needed on a Pro domain with little load (payment service)…

So I guess we have to find another solution… Too bad, really hoped I wouldn’t have to mess with GeoIP

Yeah. Maybe try running it on the workers.dev subdomain? Maybe?

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.