This commit is contained in:
Tatyana Kostromskaya
2023-10-04 15:33:15 +00:00
parent 774f139bef
commit f699b96ecf
9 changed files with 474 additions and 382 deletions

View File

@@ -299,7 +299,7 @@ describe('proxy', () => {
it('proxy settings return ProxyAgent', async () => {
process.env['https_proxy'] = 'http://127.0.0.1:8080'
const httpClient = new httpm.HttpClient()
const agent: Agent | ProxyAgent = httpClient.getAgentDispatcher('https://some-url')
const agent = httpClient.getAgentDispatcher('https://some-url')
// eslint-disable-next-line no-console
console.log(agent)
expect(agent instanceof ProxyAgent).toBe(true)
@@ -307,10 +307,10 @@ describe('proxy', () => {
it('proxyAuth is set in tunnel agent when authentication is provided', async () => {
const httpClient = new httpm.HttpClient()
const agent: Agent | ProxyAgent = httpClient.getAgentDispatcher('https://some-url')
const agent = httpClient.getAgentDispatcher('https://some-url')
// eslint-disable-next-line no-console
console.log(agent)
expect(agent instanceof Agent).toBe(true)
expect(agent).toBe(undefined)
})
})

View File

@@ -1,6 +1,6 @@
{
"name": "@actions/http-client",
"version": "3.0.0",
"version": "3.0.1",
"description": "Actions Http Client",
"keywords": [
"github",

View File

@@ -567,16 +567,14 @@ export class HttpClient {
return this._getAgent(parsedUrl)
}
getAgentDispatcher(serverUrl: string): ProxyAgent | Agent {
getAgentDispatcher(serverUrl: string): ProxyAgent | undefined {
const parsedUrl = new URL(serverUrl)
const proxyUrl = pm.getProxyUrl(parsedUrl)
const useProxy = proxyUrl && proxyUrl.hostname
if (useProxy) {
return this._getProxyAgentDispatcher(parsedUrl, proxyUrl)
}
else {
return this._getAgentDispatcher(parsedUrl)
}
return;
}
private _prepareRequest(
@@ -763,46 +761,6 @@ export class HttpClient {
return proxyAgent
}
private _getAgentDispatcher(parsedUrl: URL): Agent {
let agent;
if (this._keepAlive) {
agent = this._agentDispatcher
}
// if agent is already assigned use that agent.
if (agent) {
return agent
}
const usingSsl = parsedUrl.protocol === 'https:'
let maxSockets = 100
if (this.requestOptions) {
maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets
}
// if reusing agent across request and tunneling agent isn't assigned create a new agent
if (!agent) {
agent = new Agent(
{
pipelining: (!this._keepAlive ? 0 : 1),
}
)
this._agentDispatcher = agent
}
if (usingSsl && this._ignoreSslError) {
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
// we have to cast it to any and change it directly
agent.options = Object.assign(agent.options.connect || {}, {
rejectUnauthorized: false
})
}
return agent
}
private async _performExponentialBackoff(retryNumber: number): Promise<void> {
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber)
const ms: number = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber)