@@ -37,7 +37,11 @@ import { SDK_VERSION } from '../../core/version';
37
37
const LOG_TAG = 'Connection' ;
38
38
const X_GOOG_API_CLIENT_VALUE = `gl-node/${ process . versions . node } fire/${ SDK_VERSION } grpc/${ grpcVersion } ` ;
39
39
40
- function createMetadata ( databasePath : string , token : Token | null ) : Metadata {
40
+ function createMetadata (
41
+ databasePath : string ,
42
+ token : Token | null ,
43
+ appId : string
44
+ ) : Metadata {
41
45
hardAssert (
42
46
token === null || token . type === 'OAuth' ,
43
47
'If provided, token must be OAuth'
@@ -51,10 +55,11 @@ function createMetadata(databasePath: string, token: Token | null): Metadata {
51
55
}
52
56
}
53
57
}
54
- metadata . set ( 'x-goog-api-client' , X_GOOG_API_CLIENT_VALUE ) ;
58
+ metadata . set ( 'X-Firebase-GMPID' , appId ) ;
59
+ metadata . set ( 'X-Goog-Api-Client' , X_GOOG_API_CLIENT_VALUE ) ;
55
60
// This header is used to improve routing and project isolation by the
56
61
// backend.
57
- metadata . set ( 'google-cloud-resource-prefix ' , databasePath ) ;
62
+ metadata . set ( 'Google-Cloud-Resource-Prefix ' , databasePath ) ;
58
63
return metadata ;
59
64
}
60
65
@@ -101,7 +106,11 @@ export class GrpcConnection implements Connection {
101
106
token : Token | null
102
107
) : Promise < Resp > {
103
108
const stub = this . ensureActiveStub ( ) ;
104
- const metadata = createMetadata ( this . databasePath , token ) ;
109
+ const metadata = createMetadata (
110
+ this . databasePath ,
111
+ token ,
112
+ this . databaseInfo . appId
113
+ ) ;
105
114
const jsonRequest = { database : this . databasePath , ...request } ;
106
115
107
116
return nodePromise ( ( callback : NodeCallback < Resp > ) => {
@@ -146,7 +155,11 @@ export class GrpcConnection implements Connection {
146
155
request
147
156
) ;
148
157
const stub = this . ensureActiveStub ( ) ;
149
- const metadata = createMetadata ( this . databasePath , token ) ;
158
+ const metadata = createMetadata (
159
+ this . databasePath ,
160
+ token ,
161
+ this . databaseInfo . appId
162
+ ) ;
150
163
const jsonRequest = { ...request , database : this . databasePath } ;
151
164
const stream = stub [ rpcName ] ( jsonRequest , metadata ) ;
152
165
stream . on ( 'data' , ( response : Resp ) => {
@@ -172,7 +185,11 @@ export class GrpcConnection implements Connection {
172
185
token : Token | null
173
186
) : Stream < Req , Resp > {
174
187
const stub = this . ensureActiveStub ( ) ;
175
- const metadata = createMetadata ( this . databasePath , token ) ;
188
+ const metadata = createMetadata (
189
+ this . databasePath ,
190
+ token ,
191
+ this . databaseInfo . appId
192
+ ) ;
176
193
const grpcStream = stub [ rpcName ] ( metadata ) ;
177
194
178
195
let closed = false ;
0 commit comments