diff --git a/packages/http-client/__tests__/basics.test.ts b/packages/http-client/__tests__/basics.test.ts index d47c1200..8e76a383 100644 --- a/packages/http-client/__tests__/basics.test.ts +++ b/packages/http-client/__tests__/basics.test.ts @@ -60,7 +60,7 @@ describe('basics', () => { const body: string = await res.readBody() const obj = JSON.parse(body) expect(obj.url).toBe('https://postman-echo.com/get') - expect(obj.headers['user-agent']).toBeFalsy() + expect(obj.headers['user-agent']).toBe('actions/http-client') }) /* TODO write a mock rather then relying on a third party diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.ts index 352fa106..4dfddeb3 100644 --- a/packages/http-client/src/index.ts +++ b/packages/http-client/src/index.ts @@ -816,20 +816,16 @@ export class HttpClient { return proxyAgent } - private _getUserAgentWithOrchestrationId( - userAgent?: string - ): string | undefined { - if (!userAgent) { - return undefined - } + private _getUserAgentWithOrchestrationId(userAgent?: string): string { + const baseUserAgent = userAgent || 'actions/http-client' const orchId = process.env['ACTIONS_ORCHESTRATION_ID'] if (orchId) { // Sanitize the orchestration ID to ensure it contains only valid characters // Valid characters: 0-9, a-z, _, -, . const sanitizedId = orchId.replace(/[^a-z0-9_.\-]/gi, '_') - return `${userAgent} actions_orchestration_id/${sanitizedId}` + return `${baseUserAgent} actions_orchestration_id/${sanitizedId}` } - return userAgent + return baseUserAgent } private async _performExponentialBackoff(retryNumber: number): Promise {