Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/void/src/router/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ export function compileRouteTable(
lines.push('function __voidAnnotateRouting(response, trace) {');
lines.push(' if (!__VOID_DEV_ROUTING || !response) return response;');
lines.push(' const headers = new Headers(response.headers);');
lines.push(' headers.set("X-Void-Routing", trace);');
// Guard the set: a non-ASCII trace value throws, and must not crash the dev response.
lines.push(' try { headers.set("X-Void-Routing", trace); } catch { return response; }');
lines.push(
' return new Response(response.body, { status: response.status, statusText: response.statusText, headers });',
);
Expand Down
8 changes: 8 additions & 0 deletions packages/void/test/unit/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,14 @@ describe('X-Void-Routing dev trace header', () => {
expect(code).toContain('try { c.res.headers.set("X-Void-Routing", "pass-through"); } catch {}');
});

it('guards the __voidAnnotateRouting trace header set with try/catch', () => {
const code = compileWith({ dev: true });
// A non-ASCII trace value throws on header set; the guard must swallow it.
expect(code).toContain(
'try { headers.set("X-Void-Routing", trace); } catch { return response; }',
);
});

it('emits __VOID_DEV_ROUTING=false and strips origin fields in prod', () => {
const code = compileWith({ dev: false });
expect(code).toContain('const __VOID_DEV_ROUTING = false;');
Expand Down