diff --git a/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts b/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts index 0c8c71b3d778..dc41135c2318 100644 --- a/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts +++ b/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts @@ -14,7 +14,8 @@ import { systemErrorRetryPolicy, ServiceClientCredentials, UserAgentOptions, - getDefaultUserAgentValue as getCoreHttpDefaultUserAgentValue + getDefaultUserAgentValue as getCoreHttpDefaultUserAgentValue, + userAgentPolicy } from "@azure/core-http"; import { throttlingRetryPolicy } from "./policies/throttlingRetryPolicy"; import { TokenCredential } from "@azure/identity"; @@ -51,7 +52,7 @@ import { transformKeyValue, formatAcceptDateTime } from "./internal/helpers"; -import { tracingPolicy, isNode as coreHttpIsNode } from "@azure/core-http"; +import { tracingPolicy } from "@azure/core-http"; import { Spanner } from "./internal/tracingHelpers"; import { GetKeyValuesResponse, @@ -534,12 +535,11 @@ export function getGeneratedClientOptions( requestPolicyFactories: (defaults) => [ tracingPolicy({ userAgent }), syncTokenPolicy(syncTokens), + userAgentPolicy({ value: userAgent }), ...retryPolicies, ...defaults ], - generateClientRequestIdHeader: true, - userAgentHeaderName: getUserAgentHeaderName(), - userAgent + generateClientRequestIdHeader: true }; } @@ -557,17 +557,3 @@ export function getUserAgentPrefix(userSuppliedUserAgent: string | undefined): s return `${userSuppliedUserAgent} ${appConfigDefaultUserAgent}`; } -/** - * @ignore - * @internal - */ -function getUserAgentHeaderName(): string { - if (coreHttpIsNode) { - return "User-Agent"; - } else { - // we only need to override this when we're in the browser - // where we're (mostly) not allowed to override the User-Agent - // header. - return "x-ms-useragent"; - } -} diff --git a/sdk/appconfiguration/app-configuration/test/internal/http.spec.ts b/sdk/appconfiguration/app-configuration/test/internal/http.spec.ts index b870d53b7208..234dd1244e7d 100644 --- a/sdk/appconfiguration/app-configuration/test/internal/http.spec.ts +++ b/sdk/appconfiguration/app-configuration/test/internal/http.spec.ts @@ -5,7 +5,7 @@ import { parseSyncToken, SyncTokens } from "../../src/internal/synctokenpolicy"; import * as assert from "assert"; import { AppConfigurationClient } from "../../src"; import nock from "nock"; -import { getGeneratedClientOptions, packageVersion } from "../../src/appConfigurationClient"; +import { getUserAgentPrefix, packageVersion } from "../../src/appConfigurationClient"; import { createAppConfigurationClientForTests, assertThrowsRestError, @@ -13,7 +13,6 @@ import { } from "../testHelpers"; import * as chai from "chai"; import { Recorder } from "@azure/test-utils-recorder"; -import { isNode } from "@azure/core-http"; describe("http request related tests", function() { describe("unit tests", () => { @@ -35,41 +34,30 @@ describe("http request related tests", function() { }); }); - it("useragentheadername", () => { - let expectedUserHeaderName; - - if (isNode) { - expectedUserHeaderName = "User-Agent"; - } else { - expectedUserHeaderName = "x-ms-useragent"; - } - - let options = getGeneratedClientOptions("base-uri", new SyncTokens(), {}); - - assert.equal(options.userAgentHeaderName, expectedUserHeaderName); - }); - it("useragent", () => { - let options = getGeneratedClientOptions("base-uri", new SyncTokens(), { - userAgentOptions: { - userAgentPrefix: "MyCustomUserAgent" - } - }); + describe("with user prefix", () => { + const prefix = getUserAgentPrefix("MyCustomUserAgent"); + + chai.assert.match( + prefix, + new RegExp( + `^MyCustomUserAgent azsdk-js-app-configuration\/${packageVersion}+ core-http\/[^ ]+.+$` + ), + `Using a custom user agent` + ); + }) - chai.assert.match( - options.userAgent as string, - new RegExp( - `^MyCustomUserAgent azsdk-js-app-configuration\/${packageVersion}+ core-http\/[^ ]+.+$` - ), - `Using a custom user agent` - ); + describe("without user prefix", () => { + const prefix = getUserAgentPrefix(undefined); - options = getGeneratedClientOptions("base-uri", new SyncTokens(), {}); - chai.assert.match( - options.userAgent as string, - new RegExp(`^azsdk-js-app-configuration\/${packageVersion}+ core-http\/[^ ]+.+$`), - "Using the default user agent" - ); + chai.assert.match( + prefix, + new RegExp( + `^azsdk-js-app-configuration\/${packageVersion}+ core-http\/[^ ]+.+$` + ), + `Using the default user agent` + ); + }); }); describe("syncTokens", () => {