Skip to content

Commit 1f56b03

Browse files
authored
Added X-Firebase-Client header to FCM API calls (#236)
* Added X-Firebase-Client header to FCM API calls * Formatted for go1.11
1 parent c9b5e06 commit 1f56b03

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

messaging/messaging.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ func NewClient(ctx context.Context, c *internal.MessagingConfig) (*Client, error
662662
iidEndpoint: iidEndpoint,
663663
client: hc,
664664
project: c.ProjectID,
665-
version: "Go/Admin/" + c.Version,
665+
version: "fire-admin-go/" + c.Version,
666666
}, nil
667667
}
668668

@@ -807,7 +807,10 @@ func (c *Client) makeSendRequest(ctx context.Context, req *fcmRequest) (string,
807807
Method: http.MethodPost,
808808
URL: fmt.Sprintf("%s/projects/%s/messages:send", c.fcmEndpoint, c.project),
809809
Body: internal.NewJSONEntity(req),
810-
Opts: []internal.HTTPOption{internal.WithHeader("X-GOOG-API-FORMAT-VERSION", "2")},
810+
Opts: []internal.HTTPOption{
811+
internal.WithHeader("X-GOOG-API-FORMAT-VERSION", "2"),
812+
internal.WithHeader("X-FIREBASE-CLIENT", c.version),
813+
},
811814
}
812815

813816
resp, err := c.client.Do(ctx, request)

messaging/messaging_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var (
3838
Opts: []option.ClientOption{
3939
option.WithTokenSource(&internal.MockTokenSource{AccessToken: "test-token"}),
4040
},
41+
Version: "test-version",
4142
}
4243

4344
ttlWithNanos = time.Duration(1500) * time.Millisecond
@@ -1226,6 +1227,11 @@ func checkFCMRequest(t *testing.T, b []byte, tr *http.Request, want map[string]i
12261227
if h := tr.Header.Get("X-GOOG-API-FORMAT-VERSION"); h != "2" {
12271228
t.Errorf("X-GOOG-API-FORMAT-VERSION = %q; want = %q", h, "2")
12281229
}
1230+
1231+
clientVersion := "fire-admin-go/" + testMessagingConfig.Version
1232+
if h := tr.Header.Get("X-FIREBASE-CLIENT"); h != clientVersion {
1233+
t.Errorf("X-FIREBASE-CLIENT = %q; want = %q", h, clientVersion)
1234+
}
12291235
}
12301236

12311237
func checkIIDRequest(t *testing.T, b []byte, tr *http.Request, op string) {

0 commit comments

Comments
 (0)