Requests suddenly having no headers
Hello,
I'm working on some functions that read a specific header, and I'm suddenly realizing that no headers are getting to my code. This was working fine earlier, and it's just suddenly not and I'm not sure what has changed
I should note I'm using SvelteKit, but afaik SvelteKit doesnt change the actual request object in any way
Here is the code I have in my
hooks.server.ts
that is working fine in dev and was working fine on CF too until about 2 hours ago
Then this appears in the tail:
And, of course, data.ua is null. I find it very odd that this was all working fine, then suddenly it's not.
Any ideas about what might be causing this?5 Replies
Your log won't work, .keys() just returns an iterator, which isn't enuramble/usable by log/etc,
use something like
https://developers.cloudflare.com/workers/examples/logging-headers/
Logging headers to console · Cloudflare Workers docs
Use a Map if you need to log a Headers object to the console:
ah, whoops.
It's now showing some headers, but only 3. (if im not mistaken, there should at least be the cf-specific headers, right?)
There should be more headers yea, I haven't used Sveltekit hooks before myself so I'm not sure exactly how they work, only thing I can think is testing in non-local if you're not already, and looking into the event object. If the request object is untransformed it should have everything, perhaps there is event.headers or something else, not sure
the sveltekit docs claim that it is the "original" request object
![](https://cdn.answeroverflow.com/1125969467004952636/image.png)
there does not appear to be an event.headers
https://kit.svelte.dev/docs/types#public-types-requestevent
It works perfectly fine when running a sveltekit dev server. However, when deploying to pages it has the described behaviour. The weird thing is that is was working fine earlier today when deployed
The issue ended up being due to (my mishandling of) sveltekit's handling of
fetch
inside server requests
The initial request would have all the correct headers, but then all of the internal sub-requests would just have the 3 headers sent above. I ended up only trying to read the user-agent header if the host
header is present (which it should be for all non-internal requests), then the issue is fixed!