Add default user-agent 'actions/http-client' when none provided
Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<void> {
|
||||
|
||||
Reference in New Issue
Block a user