Skip to content

BUG: setHeaders throws when adding second Server-Timing-header (should be appended) #14681

@tolu

Description

@tolu

Describe the problem

setHeaders from getRequestEvent() fails here when attempting to set multiple Server-Timing headers.

# error in terminal
Error: "Server-Timing" header is already set
    at setHeaders (node_modules/@sveltejs/kit/src/runtime/server/respond.js, <anonymous>:147:17)
    ...

Describe the proposed solution

Have setHeaders handle Server-Timing like Headers.append if the key already exist in the map.

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 🫶

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions