What headers are available in my Worker

In the FAQ there is a question “What headers are available in my Worker?” where we can read “Cloudflare-specific headers will conveniently let you know […] what type of device the user is using”. But the linked documentation doesn’t have any mention of a device type header, so was that a mistake? I was hoping not, because I’ve always thought it would be very convenient if some header had information telling us whether the user-agent is a robot, mobile, tablet, or desktop. Finding a good UA-detection library and keeping it up to date is quite a pain.

Great question! Here is an example of the headers seen by a request I just tested:

accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
accept-encoding: gzip
accept-language: en-US,en;q=0.9
cf-connecting-ip: 2606:4500:2001:10b:0:1:0:70
cf-device-type: desktop
cf-ipcountry: US
cf-ray: 3fc8c398cbbb7f06
cf-visitor: {"scheme":"https"}
connection: Keep-Alive
host: x.com
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
x-forwarded-proto: https

We do do desktop vs mobile classification, but it’s a feature only included with our Enterprise plans unfortunately. As you say, it is challenging to keep a library like that up to date. You can bundle one into your Worker though, how about https://github.com/faisalman/ua-parser-js?

1 Like

Ah, Enterprise only, figures.

You should add a mention of cf-device-type to the docs, I’m sure you’d get more people interested in the Enterprise plan :slight_smile:

Hello, I’m on an enterprise plan and I’m not seeing the cf-device-type header in my workers when working in the dashboard while it’s present in production requests and in requests from the worker to the backend.

In the Testing of the workers’ tab the headers must be configured by you. The requests are empty (not even a connecting IP is present).

1 Like

Not really. These other Cloudflare-specific headers are visibile when I do a console.log(new Map(request.headers)): cf-connecting-ip, cf-ipcountry cf-ray and cf-visitor.

1 Like

So you are in the preview, not in the the testing tab. Unfortunately I can’t test that for you as that header is specific to Enterprise. Have you tried contacting you Cloudflare Engineer?

I can verify that these headers are present in the preview
but not in the ‘Testing’ tab:

{"cf-connecting-ip" ...}
{"cf-ipcountry" ...}
{"cf-ray" ...}
{"cf-visitor" ...}

but not

{"cf-device-type: ...}

Any reasons why device is missing?

cf-device-type I believe is enterprise level account.

If you have enterprise account you should contact you account manager