Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rhodgkins authored Jan 29, 2025
2 parents bd1b9d3 + 8f46a4f commit f900f6c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
- Add onCallGenkit (#1655)
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-functions",
"version": "6.2.0",
"version": "6.3.0",
"description": "Firebase SDK for Cloud Functions",
"keywords": [
"firebase",
Expand Down
45 changes: 31 additions & 14 deletions spec/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export function runHandler(
// MockResponse mocks an express.Response.
// This class lives here so it can reference resolve and reject.
class MockResponse {
private sentBody = "";
private sentBody: string | undefined;
private statusCode = 0;
private headers: { [name: string]: string } = {};
private callback: () => void;
private writeCalled = false;

constructor() {
request.on("close", () => this.end());
Expand All @@ -71,29 +72,45 @@ export function runHandler(
}

public send(sendBody: any) {
const toSend = typeof sendBody === "object" ? JSON.stringify(sendBody) : sendBody;
const body = this.sentBody ? this.sentBody + ((toSend as string) || "") : toSend;

resolve({
status: this.statusCode,
headers: this.headers,
body,
});
if (this.callback) {
this.callback();
if (this.writeCalled) {
throw Error("Cannot set headers after they are sent to the client");
}

const toSend = typeof sendBody === "object" ? JSON.stringify(sendBody) : sendBody;
const body =
typeof this.sentBody === "undefined"
? toSend
: this.sentBody + String(toSend || "");
this.end(body);
}

public write(writeBody: any, cb?: () => void) {
this.sentBody += typeof writeBody === "object" ? JSON.stringify(writeBody) : writeBody;
this.writeCalled = true;

if (typeof this.sentBody === "undefined") {
this.sentBody = writeBody;
} else {
this.sentBody += typeof writeBody === "object" ? JSON.stringify(writeBody) : writeBody;
}
if (cb) {
setImmediate(cb);
}
return true;
}

public end() {
this.send(undefined);
public end(body?: unknown) {
if (body) {
this.write(body);
}
resolve({
status: this.statusCode,
headers: this.headers,
body: this.sentBody,
});

if (this.callback) {
this.callback();
}
}

public on(event: string, callback: () => void) {
Expand Down
3 changes: 2 additions & 1 deletion src/common/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,8 @@ function wrapOnCallHandler<Req = any, Res = any, Stream = unknown>(
const { status } = httpErr.httpErrorCode;
const body = { error: httpErr.toJSON() };
if (version === "gcfv2" && req.header("accept") === "text/event-stream") {
res.send(encodeSSE(body));
res.write(encodeSSE(body));
res.end();
} else {
res.status(status).send(body);
}
Expand Down

0 comments on commit f900f6c

Please sign in to comment.