Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions spec/common/providers/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
},
});
});
});
});

Expand Down
8 changes: 7 additions & 1 deletion src/common/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,12 @@ function wrapOnCallHandler<Req = any, Res = any>(
}

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") {
Expand Down Expand Up @@ -832,7 +838,7 @@ function wrapOnCallHandler<Req = any, Res = any>(

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);
Expand Down
Loading