Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 20 additions & 0 deletions spec/common/providers/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,26 @@
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" },
},
(req, resp) => {

Check failure on line 817 in spec/common/providers/https.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'req' is defined but never used

Check failure on line 817 in spec/common/providers/https.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'resp' is defined but never used
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'" } });

Check failure on line 823 in spec/common/providers/https.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Replace `·"error":·{·"status":·"INVALID_ARGUMENT",·"message":·"Unsupported·Accept·header·'text/event-stream'"·}` with `⏎········error:·{⏎··········status:·"INVALID_ARGUMENT",⏎··········message:·"Unsupported·Accept·header·'text/event-stream'",⏎········},⏎·····`
});
});
});

Expand Down
12 changes: 9 additions & 3 deletions src/common/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,12 @@
}

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'")

Check failure on line 788 in src/common/providers/https.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Replace `'invalid-argument',·"Unsupported·Accept·header·'text/event-stream'")` with `"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,11 +838,11 @@

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);
}
}
};
}
}

Check failure on line 847 in src/common/providers/https.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Insert `;`
};

Check failure on line 848 in src/common/providers/https.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Delete `;`
Loading