I have a cloud run function n that streams data and the API gateway in front to protect the endpoint. If I call the function directly it streams the data fine, but if I call it through the gateway it buffers the whole stream until sending all at once. Does API gateway allow streaming? Do I need specific openAPI configuration?
The following function and config do not work
functions.http("simulateStream", async (req, res) => {
res.setHeader("Content-Type", "text/event-stream");
res.setHeader("Cache-Control", "no-cache");
res.setHeader("Connection", "keep-alive");
let counter = 0;
const interval = setInterval(() => {
counter++;
res.write(`data: ${counter}\n\n`);
res.flush = res.flush || (() => {});
res.flush();
if (counter > 50) {
clearInterval(interval);
res.end();
}
}, 1000);
});
and config:
swagger: "2.0"
info:
title: test-api
description: test-api
version: 1.0.0
schemes:
- https
produces:
- application/json
paths:
/simulateStream:
get:
summary: Simulate a stream
operationId: simulateStream
x-google-backend:
address: https://tst.cloudfunctions.net/simulateStream
responses:
"200":
description: A successful response
schema:
type: string