X-country header returning incorrect code

Hi it seems the super helpful x-country header is returning DE for all my endpoints.

*The following is irrelevant to the actual problem.*

Example GET to “netlify.com

content-type: text/html; charset=UTF-8
content-length: 512719
accept-ranges: bytes
cache-control: public, max-age=0, must-revalidate
date: Wed, 05 Jul 2023 19:52:24 GMT
etag: "f72c892a2845e2df087eec540632583d-ssl"
server: Netlify
server-timing: cr;desc="hit-fresh", ds;dur=3, dc;desc="aws-lhr", cg;desc="global-production", cl;dur=512719, dist;dur=135, tls;desc="reused"
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-cnm-signal-k: 1:69350086-d20e-4b5a-84cf-bf367a848374:64a5bb272f7081000839fdbb:1688582995365
x-nf-request-id: 01H4KSSX29MCK1TEAP7H37BSWG
x-cache: Miss from cloudfront
via: 1.1 f33cf28b2f4af4733ccec76b9bf56bc6.cloudfront.net (CloudFront)
x-amz-cf-pop: LHR50-P4
x-amz-cf-id: nVko6rso2KGCtWpPpcXHGIi5PbZzkH-fiu24NhdrjNlJTscLZpofpw==
age: 3117

I don’t believe this functionality ever existed :thinking: It should still exist in Edge Functions (and probably Functions, though I’m not 100% sure about the latter).

1 Like

Hmm it seems that a country code is still returned from my lambda endpoint. I am sending a request from the UK but x-country is returning DE (The functions server is in Germany)

Is x-country based on where the request is coming from or where the request is handled?

FYI the Vercel equivalent is x-vercel-ip-country

Seems to be related to proxies according to this:

So I am using lambda functions so proxies shouldn’t be a problem. Also the header can be found in a request it just isn’t for the correct country. I think I have figured the problem out though.

  1. Request sent from Netlify Site to my API (Request is sent via functions hosted in Germany)

  2. API will fetch headers from incoming requests (assuming the country will be DE because the request is coming from a function hosted in Germany)

So to get the country code of the user who sends the request via the Netlify Site, I think the only way is to pass the x-country header to the API instead of calculating it natively from the API.

Bit confusing but I think that’s the best way to go about it?