diff --git a/spec/common/providers/https.spec.ts b/spec/common/providers/https.spec.ts index 050577564..55f698575 100644 --- a/spec/common/providers/https.spec.ts +++ b/spec/common/providers/https.spec.ts @@ -802,6 +802,31 @@ describe("onCallHandler", () => { const data = [`data: {"error":{"message":"INTERNAL","status":"INTERNAL"}}`]; expect(resp.body).to.equal([...data, ""].join("\n")); }); + + it("always returns error for v1 callables", async () => { + const mockReq = mockRequest( + { message: "hello streaming" }, + "application/json", + {}, + { accept: "text/event-stream" } + ) as any; + const fn = https.onCallHandler( + { + cors: { origin: true, methods: "POST" }, + }, + () => { + return "hello world"; + }, + "gcfv1" + ); + const resp = await runHandler(fn, mockReq); + expect(JSON.parse(resp.body)).to.deep.equal({ + error: { + status: "INVALID_ARGUMENT", + message: "Unsupported Accept header 'text/event-stream'", + }, + }); + }); }); }); diff --git a/src/common/providers/https.ts b/src/common/providers/https.ts index d10696837..d798a2579 100644 --- a/src/common/providers/https.ts +++ b/src/common/providers/https.ts @@ -782,6 +782,12 @@ function wrapOnCallHandler( } const acceptsStreaming = req.header("accept") === "text/event-stream"; + + if (acceptsStreaming && version === "gcfv1") { + // streaming responses are not supported in v1 callable + throw new HttpsError("invalid-argument", "Unsupported Accept header 'text/event-stream'"); + } + const data: Req = decode(req.body.data); let result: Res; if (version === "gcfv1") { @@ -832,7 +838,7 @@ function wrapOnCallHandler( const { status } = httpErr.httpErrorCode; const body = { error: httpErr.toJSON() }; - if (req.header("accept") === "text/event-stream") { + if (version === "gcfv2" && req.header("accept") === "text/event-stream") { res.send(encodeSSE(body)); } else { res.status(status).send(body);