mirror of
https://github.com/actions/toolkit.git
synced 2026-08-20 00:00:14 +02:00
Add default user-agent 'actions/http-client' when none provided
Co-authored-by: TingluoHuang <[email protected]>
This commit is contained in:
co-authored by
TingluoHuang
parent
97f5a6f0dc
commit
3a191eecf6
@@ -60,7 +60,7 @@ describe('basics', () => {
|
|||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('https://postman-echo.com/get')
|
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
|
/* TODO write a mock rather then relying on a third party
|
||||||
|
|||||||
@@ -816,20 +816,16 @@ export class HttpClient {
|
|||||||
return proxyAgent
|
return proxyAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getUserAgentWithOrchestrationId(
|
private _getUserAgentWithOrchestrationId(userAgent?: string): string {
|
||||||
userAgent?: string
|
const baseUserAgent = userAgent || 'actions/http-client'
|
||||||
): string | undefined {
|
|
||||||
if (!userAgent) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
const orchId = process.env['ACTIONS_ORCHESTRATION_ID']
|
const orchId = process.env['ACTIONS_ORCHESTRATION_ID']
|
||||||
if (orchId) {
|
if (orchId) {
|
||||||
// Sanitize the orchestration ID to ensure it contains only valid characters
|
// Sanitize the orchestration ID to ensure it contains only valid characters
|
||||||
// Valid characters: 0-9, a-z, _, -, .
|
// Valid characters: 0-9, a-z, _, -, .
|
||||||
const sanitizedId = orchId.replace(/[^a-z0-9_.\-]/gi, '_')
|
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> {
|
private async _performExponentialBackoff(retryNumber: number): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user