Cf-Ipcountry header value for Nothern Ireland

What would be the value of the Cf-Ipcountry header for an IP address originating from Northern Ireland?

I’m assuming it would be GB according to ISO 3166-1 alpha-2 - Wikipedia.

Just want to double check there are no user-assigned code elements used as per below.

User-assigned code elements

  • The code XI is being used by the UK Government as an EORI number

@michael lives in the area and probably knows.

Detecting Northern Ireland is indeed close to my heart!

GB is the relevant code.

To detect Northern Ireland I use a Worker which also looks at the request.cf.city value, and compares it to a list of 100+ cities in Northern Ireland. (Happy to share the list if you message me). You need to be on a Business or Enterprise plan to see that data on the CF object.

I previously requested that Cloudflare add a request.cf.regionCode or request.cf.region containing the subdivision 1 ISO code, which would enable access to GB-NIR. I’ve just looked at the documentation, and it appears my request was delivered (region and regionCode are the ones you want). I’ve never tested that myself to confirm.

5 Likes

Thanks a lot @michael, very helpful.

If request.cf.regionCode or request.cf.region works that sounds ideal.

  1. My understanding is that these are only available to the Edge worker, correct?
  2. Assuming yes, how would you go about forwarding this region information to the application? One idea I have is to in the worker create a new request to a Northern Ireland specific URL. Another idea is to create a new request where the region information is somehow included in the header to expose this information to the application.

Thanks again.

There are lots of ways to do this, and really depends on your application design and personal preference.

The request.cf object is only available in a Worker.

Detecting GB-NIR has generally been difficult. Several of the databases available do a terrible job of identifying users in that territory. A few of the large UK ISPs run their network on a whole country basis, so a user in NI will get IP addresses from a large pool that is shared across the whole of the UK. My experience is that the MaxMind GeoIP2 database that Cloudflare use is accurate, but your mileage may vary. The reason I say this is that you might need to account for user-selection, rather than a decision purely made on the basis of the regionCode that Cloudflare detect. (I do not allow user selection in my application, but your use case may be different.)

One thing you can do is to append a query parameter in the Worker, and then do a fetch. The advantage here is that the public facing URL does not change, but the query parameter becomes part of the cache key, so your backend will not receive a significant increase in requests.

You could have a public facing URL that includes a country/region code, and if the region code does not match the detected region issue a redirect, otherwise do a fetch.

Adding a header in the worker is fine, but depends on whether you allow the content to be cached in Cloudflare. I think query parameter or URL pattern is probably easier, especially for logging and debugging.

1 Like

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