(
encoding: SupportedEncoding,
statusCode: SupportedStatus,
options: { chunked?: boolean } = {},
)
| 41 | } |
| 42 | |
| 43 | async 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 | |
| 70 | describe('fetchWithProxy compressed responses', () => { |
| 71 | beforeEach(() => { |
no test coverage detected
searching dependent graphs…