fix: flush proxied event stream headers
This commit is contained in:
@@ -334,6 +334,31 @@ describe('same-origin canary gateway', () => {
|
|||||||
await reader?.cancel();
|
await reader?.cancel();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('flushes SSE response headers before the first upstream event', async () => {
|
||||||
|
const upstream = createServer((_request, response) => {
|
||||||
|
response.writeHead(200, {
|
||||||
|
'content-type': 'text/event-stream',
|
||||||
|
'cache-control': 'no-cache',
|
||||||
|
});
|
||||||
|
response.flushHeaders();
|
||||||
|
});
|
||||||
|
servers.push(upstream);
|
||||||
|
const gateway = await startGateway(await fixtureDist(), await listen(upstream));
|
||||||
|
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeout = setTimeout(() => controller.abort(), 500);
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${gateway.origin}/api/v1/events`, {
|
||||||
|
signal: controller.signal,
|
||||||
|
});
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.headers.get('content-type')).toBe('text/event-stream');
|
||||||
|
await response.body?.cancel();
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('has reversible, idempotent start/stop lifecycle', async () => {
|
it('has reversible, idempotent start/stop lifecycle', async () => {
|
||||||
const gateway = createCanaryGateway({ distDir: await fixtureDist(), port: 0, upstreamPort: 1 });
|
const gateway = createCanaryGateway({ distDir: await fixtureDist(), port: 0, upstreamPort: 1 });
|
||||||
gateways.push(gateway);
|
gateways.push(gateway);
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ async function proxyRequest(
|
|||||||
upstreamResponse.statusMessage,
|
upstreamResponse.statusMessage,
|
||||||
withoutHopByHop(upstreamResponse.headers),
|
withoutHopByHop(upstreamResponse.headers),
|
||||||
);
|
);
|
||||||
|
response.flushHeaders();
|
||||||
pipeline(upstreamResponse, response)
|
pipeline(upstreamResponse, response)
|
||||||
.then(resolvePromise)
|
.then(resolvePromise)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user