-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the problem
I really like observability and traceability in chrome dev-tools and as such I fancy the Server-Timing
header.
I noticed that setHeaders
from getRequestEvent()
fails here when attempting to set multiple Server-Timing
headers. This is hard to get around since I set the headers in the code where async stuff happens
# error in terminal
Error: "Server-Timing" header is already set
at setHeaders (node_modules/@sveltejs/kit/src/runtime/server/respond.js, <anonymous>:147:17)
...
This, given the current implementation, is expected behaviour since Server-Timing
should be appended rather than set.
Describe the proposed solution
An even better solution would ofc be if setHeaders
handled Server-Timing
like .append
in the implementation (perhaps several adapters, my usecase is node/deno).
If fixing this aligns with your thoughts, I'd be happy to provide a PR 🙏
Alternatives considered
I've worked around the problem by doing something like this:
/** somewhere in the code */
setHeaders({
[`x-timing-${randomUUID()}`]: `${timingName};dur=${time}`,
});
/** server.hooks.ts */
response.headers.keys().filter((k) => k.startsWith('x-timing-')).forEach((k) => {
const v = response.headers.get(k);
response.headers.append('Server-Timing', v!);
response.headers.delete(k);
});
response.headers.append('Server-Timing', `total;dur=${Date.now() - start}`);
Importance
would make my life easier
Additional Information
Thanks for this amazingly fun framework to work with 🫶