Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for streaming responses for v1 callables. #1645

Merged
merged 3 commits into from
Nov 21, 2024
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