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?


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: