diff --git a/auth/auth.go b/auth/auth.go index d6299611..8884bf68 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "os" + "runtime" "strings" "time" @@ -137,6 +138,7 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error) hc.CreateErrFn = handleHTTPError hc.Opts = []internal.HTTPOption{ internal.WithHeader("X-Client-Version", fmt.Sprintf("Go/Admin/%s", conf.Version)), + internal.WithHeader("x-goog-api-client", fmt.Sprintf("gl-go/%s fire-admin/%s", runtime.Version(), conf.Version)), } baseURL := defaultAuthURL diff --git a/auth/auth_test.go b/auth/auth_test.go index 30fbde88..c0c8f91f 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -23,6 +23,7 @@ import ( "log" "net/http" "os" + "runtime" "strings" "syscall" "testing" @@ -1451,6 +1452,12 @@ func checkBaseClient(client *Client, wantProjectID string) error { return fmt.Errorf("version = %q; want = %q", version, wantVersion) } + xGoogApiClientHeader := req.Header.Get("x-goog-api-client") + wantXGoogApiClientHeader := fmt.Sprintf("gl-go/%s fire-admin/%s", runtime.Version(), testVersion) + if xGoogApiClientHeader != wantXGoogApiClientHeader { + return fmt.Errorf("x-goog-api-client header = %q; want = %q", xGoogApiClientHeader, wantXGoogApiClientHeader) + } + return nil } diff --git a/auth/user_mgt_test.go b/auth/user_mgt_test.go index ffa48655..55cfd3a4 100644 --- a/auth/user_mgt_test.go +++ b/auth/user_mgt_test.go @@ -24,6 +24,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "runtime" "sort" "strconv" "strings" @@ -2315,6 +2316,12 @@ func echoServer(resp interface{}, t *testing.T) *mockAuthServer { t.Errorf("X-Client-Version header = %q; want: %q", gh, wh) } + gh = r.Header.Get("x-goog-api-client") + wh = fmt.Sprintf("gl-go/%s fire-admin/%s", runtime.Version(), testVersion) + if gh != wh { + t.Errorf("x-goog-api-client header = %q; want: %q", gh, wh) + } + for k, v := range s.Header { w.Header().Set(k, v) } diff --git a/messaging/messaging.go b/messaging/messaging.go index 2a846166..12271a9a 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -23,6 +23,7 @@ import ( "fmt" "net/http" "regexp" + "runtime" "strconv" "strings" "time" @@ -897,6 +898,7 @@ func newFCMClient(hc *http.Client, conf *internal.MessagingConfig, messagingEndp client.Opts = []internal.HTTPOption{ internal.WithHeader(apiFormatVersionHeader, apiFormatVersion), internal.WithHeader(firebaseClientHeader, version), + internal.WithHeader("x-goog-api-client", fmt.Sprintf("gl-go/%s fire-admin/%s", runtime.Version(), conf.Version)), } return &fcmClient{ diff --git a/messaging/messaging_test.go b/messaging/messaging_test.go index 7421fb7e..a782da8c 100644 --- a/messaging/messaging_test.go +++ b/messaging/messaging_test.go @@ -21,6 +21,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "runtime" "testing" "time" @@ -1394,6 +1395,10 @@ func checkFCMRequest(t *testing.T, b []byte, tr *http.Request, want map[string]i if h := tr.Header.Get("X-FIREBASE-CLIENT"); h != clientVersion { t.Errorf("X-FIREBASE-CLIENT = %q; want = %q", h, clientVersion) } + xGoogApiClientHeader := "gl-go/" + runtime.Version() + " fire-admin/" + testMessagingConfig.Version + if h := tr.Header.Get("x-goog-api-client"); h != xGoogApiClientHeader { + t.Errorf("x-goog-api-client header = %q; want = %q", h, xGoogApiClientHeader) + } } var httpErrors = []struct {