fix proxy debug undici response header capture (#442)
This commit is contained in:
@@ -2,6 +2,7 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|||||||
import { mkdtempSync } from 'node:fs';
|
import { mkdtempSync } from 'node:fs';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
|
import { Response } from 'undici';
|
||||||
|
|
||||||
type DbModule = typeof import('../db/index.js');
|
type DbModule = typeof import('../db/index.js');
|
||||||
type StoreModule = typeof import('./proxyDebugTraceStore.js');
|
type StoreModule = typeof import('./proxyDebugTraceStore.js');
|
||||||
@@ -183,4 +184,18 @@ describe('proxyDebugTraceStore', () => {
|
|||||||
expect(typeof bodyPayload.preview).toBe('string');
|
expect(typeof bodyPayload.preview).toBe('string');
|
||||||
expect(bodyPayload.preview).toContain('"model": "gpt-5.4"');
|
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',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -70,8 +70,12 @@ function stringifyDebugValue(value: unknown, maxBytes: number): string | null {
|
|||||||
function normalizeHeadersValue(value: HeadersLike): Record<string, unknown> | null {
|
function normalizeHeadersValue(value: HeadersLike): Record<string, unknown> | null {
|
||||||
if (!value) return null;
|
if (!value) return null;
|
||||||
|
|
||||||
if (typeof Headers !== 'undefined' && value instanceof Headers) {
|
const headerEntries = value as { entries?: unknown; get?: unknown };
|
||||||
return Object.fromEntries([...value.entries()].sort((left, right) => left[0].localeCompare(right[0])));
|
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)) {
|
if (typeof value !== 'object' || Array.isArray(value)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user