Workers a good solution to adding GeoCookies?
Hey everyone! I've got a client that's asking us to add cookies that identify geolocation before it hits the server (otherwise, if the server sets it, it won't be available on initial request). Is something like this a good use case for workers?
I've seen a lot of examples where workers provide routes that can be used to invoke the worker script. But can it act at the request layer to modify it before it hits the host?
Thanks!!
10 Replies
Does it need to be a cookie specifically, or just a header?
Yeah I had the same want. I do see that CF provides headers, and I could print the headers into script through a server-side transform - but the client wants this in a cookie (which would have to be set preflight)
Is this something Workers can do, or am I barking up the wrong tree?
Definitely, but I'm checking rn to see if you could do it in a Rule. If so, then it would be free
oh interesting
appreciate the gesture!
Do Header rules automatically get coallesced?
I agree! Just one of those crazy large-corp shenanigans.
sounds like a good idea - I've never authored a Worker. Have only really used CF for WAF and basic network tasks. The worker example code I've found seems to serve pages outright. Are there any that deal with setting cookies whilst still serving the request from the host?
If it is toward the origin, wouldn’t that also work as a Request Header Transform?
Makes sense - thank you so much
Now you got me curious, wondering if you can simplify it with a
concat
...
Wut? Apparently you can't edit the cookie
header with Transforms...
Like, not even that it might be difficult to format them, just that it fails to deploy because you can't perform a set
operation on a cookie
header
Well, that quickly nuked my hopes
Wonder if that is because you could mess with the CF Detection Cookie, or that you might bungle the header entirely...
Maybe a warning, instead of a full block... idkThanks for pointing me in the right direction. I was able to get the data into a cookie like so: