1
0
forked from boos/BoosAPI

fix proxy debug undici response header capture (#442)

This commit is contained in:
Cita
2026-04-06 13:16:46 +08:00
committed by GitHub
parent 2f0e63a1e0
commit 2b9200ea7c
2 changed files with 21 additions and 2 deletions
@@ -2,6 +2,7 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { Response } from 'undici';
type DbModule = typeof import('../db/index.js');
type StoreModule = typeof import('./proxyDebugTraceStore.js');
@@ -183,4 +184,18 @@ describe('proxyDebugTraceStore', () => {
expect(typeof bodyPayload.preview).toBe('string');
expect(bodyPayload.preview).toContain('"model": "gpt-5.4"');
});
it('normalizes undici response headers for proxy debug capture', () => {
const response = new Response('ok', {
headers: {
'content-type': 'application/json',
'x-trace-id': 'trace-123',
},
});
expect(store.normalizeProxyDebugResponseHeaders(response.headers)).toEqual({
'content-type': 'application/json',
'x-trace-id': 'trace-123',
});
});
});
+6 -2
View File
@@ -70,8 +70,12 @@ function stringifyDebugValue(value: unknown, maxBytes: number): string | null {
function normalizeHeadersValue(value: HeadersLike): Record<string, unknown> | null {
if (!value) return null;
if (typeof Headers !== 'undefined' && value instanceof Headers) {
return Object.fromEntries([...value.entries()].sort((left, right) => left[0].localeCompare(right[0])));
const headerEntries = value as { entries?: unknown; get?: unknown };
if (typeof headerEntries.get === 'function' && typeof headerEntries.entries === 'function') {
return Object.fromEntries(
[...headerEntries.entries.call(value) as Iterable<[string, string]>]
.sort((left, right) => left[0].localeCompare(right[0])),
);
}
if (typeof value !== 'object' || Array.isArray(value)) {