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

Add x-goog-request-params to request header. #7440

Merged
merged 22 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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
5 changes: 5 additions & 0 deletions .changeset/eighty-roses-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

Add `x-goog-request-params` to REST request header.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about release notes stating what is fixed in terms of what the customer understands?

For example this could be "Fixed issue where count and lite API queries did not work with named databases."

13 changes: 11 additions & 2 deletions packages/firestore/src/remote/rest_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

import { SDK_VERSION } from '../../src/core/version';
import { Token } from '../api/credentials';
import { DatabaseId, DatabaseInfo } from '../core/database_info';
import {
DatabaseId,
DatabaseInfo,
DEFAULT_DATABASE_NAME
} from '../core/database_info';
import { debugAssert } from '../util/assert';
import { generateUniqueDebugId } from '../util/debug_uid';
import { FirestoreError } from '../util/error';
Expand Down Expand Up @@ -85,7 +89,12 @@ export abstract class RestConnection implements Connection {
const url = this.makeUrl(rpcName, path);
logDebug(LOG_TAG, `Sending RPC '${rpcName}' ${streamId}:`, url, req);

const headers = {};
const headers: StringMap = {
'x-goog-request-params':
this.databaseId.database === DEFAULT_DATABASE_NAME
? `project_id=${this.databaseId.projectId}`
: `project_id=${this.databaseId.projectId}&database_id=${this.databaseId.database}`
dconeybe marked this conversation as resolved.
Show resolved Hide resolved
};
this.modifyHeadersForRequest(headers, authToken, appCheckToken);

return this.performRPCRequest<Req, Resp>(rpcName, url, headers, req).then(
Expand Down
6 changes: 4 additions & 2 deletions packages/firestore/test/unit/remote/rest_connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ describe('RestConnection', () => {
'Content-Type': 'text/plain',
'X-Firebase-GMPID': 'test-app-id',
'X-Goog-Api-Client': `gl-js/ fire/${SDK_VERSION}`,
'x-firebase-appcheck': 'some-app-check-token'
'x-firebase-appcheck': 'some-app-check-token',
'x-goog-request-params': 'project_id=testproject'
});
});

Expand All @@ -111,7 +112,8 @@ describe('RestConnection', () => {
expect(connection.lastHeaders).to.deep.equal({
'Content-Type': 'text/plain',
'X-Firebase-GMPID': 'test-app-id',
'X-Goog-Api-Client': `gl-js/ fire/${SDK_VERSION}`
'X-Goog-Api-Client': `gl-js/ fire/${SDK_VERSION}`,
'x-goog-request-params': 'project_id=testproject'
// Note: AppCheck token should not exist here.
});
});
Expand Down
4 changes: 2 additions & 2 deletions scripts/emulator-testing/emulators/firestore-emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class FirestoreEmulator extends Emulator {

constructor(port: number, projectId = 'test-emulator') {
super(
'cloud-firestore-emulator-v1.14.4.jar',
'cloud-firestore-emulator-v1.18.1.jar',
// Use locked version of emulator for test to be deterministic.
// The latest version can be found from firestore emulator doc:
// https://firebase.google.com/docs/firestore/security/test-rules-emulator
'https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.14.4.jar',
'https://storage.googleapis.com/firebase-preview-drop/emulator/cloud-firestore-emulator-v1.18.1.jar',
port
);
this.projectId = projectId;
Expand Down