MCPcopy
hub / github.com/promptfoo/promptfoo / startCompressedServer

Function startCompressedServer

test/fetch.compression.test.ts:43–68  ·  view source on GitHub ↗
(
  encoding: SupportedEncoding,
  statusCode: SupportedStatus,
  options: { chunked?: boolean } = {},
)

Source from the content-addressed store, hash-verified

41}
42
43async function startCompressedServer(
44 encoding: SupportedEncoding,
45 statusCode: SupportedStatus,
46 options: { chunked?: boolean } = {},
47): Promise<string> {
48 const body = compress(encoding, Buffer.from(JSON.stringify(payload)));
49 return startServer((_req, res) => {
50 const headers: Record<string, string> = {
51 'content-encoding': encoding,
52 'content-type': 'application/json',
53 };
54 if (!options.chunked) {
55 headers['content-length'] = String(body.length);
56 }
57 res.writeHead(statusCode, headers);
58
59 if (options.chunked) {
60 // Force chunked transfer-encoding by emitting in two writes without content-length.
61 const mid = Math.max(1, Math.floor(body.length / 2));
62 res.write(body.subarray(0, mid));
63 res.end(body.subarray(mid));
64 } else {
65 res.end(body);
66 }
67 });
68}
69
70describe('fetchWithProxy compressed responses', () => {
71 beforeEach(() => {

Callers 1

Calls 3

compressFunction · 0.85
startServerFunction · 0.70
writeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…