Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13e0ce9cf7 | ||
|
|
eae1b66cb0 | ||
|
|
129f884271 | ||
|
|
0faced6a0b |
@@ -1,7 +1,6 @@
|
|||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import * as https from 'https'
|
import * as https from 'https'
|
||||||
import { ProxyServer, createProxy } from "proxy";
|
import proxy from 'proxy'
|
||||||
import { ProxyAgent, fetch as undiciFetch } from "undici";
|
|
||||||
|
|
||||||
// Default values are set when the module is imported, so we need to set proxy first.
|
// Default values are set when the module is imported, so we need to set proxy first.
|
||||||
const proxyUrl = 'http://127.0.0.1:8081'
|
const proxyUrl = 'http://127.0.0.1:8081'
|
||||||
@@ -17,7 +16,7 @@ describe('@actions/github', () => {
|
|||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Start proxy server
|
// Start proxy server
|
||||||
proxyServer = createProxy()
|
proxyServer = proxy()
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
const port = Number(proxyUrl.split(':')[2])
|
const port = Number(proxyUrl.split(':')[2])
|
||||||
proxyServer.listen(port, () => resolve())
|
proxyServer.listen(port, () => resolve())
|
||||||
@@ -50,7 +49,6 @@ describe('@actions/github', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const octokit = getOctokit(token)
|
const octokit = getOctokit(token)
|
||||||
|
|
||||||
const branch = await octokit.rest.repos.getBranch({
|
const branch = await octokit.rest.repos.getBranch({
|
||||||
owner: 'actions',
|
owner: 'actions',
|
||||||
repo: 'toolkit',
|
repo: 'toolkit',
|
||||||
@@ -66,17 +64,6 @@ describe('@actions/github', () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
process.env['https_proxy'] = proxyUrl
|
process.env['https_proxy'] = proxyUrl
|
||||||
// const myFetch: typeof undiciFetch = (url, opts) => {
|
|
||||||
// return undiciFetch(url, {
|
|
||||||
// ...opts,
|
|
||||||
// dispatcher: new ProxyAgent({
|
|
||||||
// uri: proxyUrl,
|
|
||||||
// keepAliveTimeout: 10,
|
|
||||||
// keepAliveMaxTimeout: 10,
|
|
||||||
// }),
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
const octokit = getOctokit(token)
|
const octokit = getOctokit(token)
|
||||||
|
|
||||||
const repository = await octokit.graphql(
|
const repository = await octokit.graphql(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import { createProxy } from 'proxy'
|
import proxy from 'proxy'
|
||||||
import {getOctokit} from '../src/github'
|
import {getOctokit} from '../src/github'
|
||||||
import {GitHub, getOctokitOptions} from '../src/utils'
|
import {GitHub, getOctokitOptions} from '../src/utils'
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ describe('@actions/github', () => {
|
|||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Start proxy server
|
// Start proxy server
|
||||||
proxyServer = createProxy()
|
proxyServer = proxy()
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
const port = Number(proxyUrl.split(':')[2])
|
const port = Number(proxyUrl.split(':')[2])
|
||||||
proxyServer.listen(port, () => resolve())
|
proxyServer.listen(port, () => resolve())
|
||||||
|
|||||||
Generated
+300
-431
File diff suppressed because it is too large
Load Diff
@@ -38,14 +38,12 @@
|
|||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/http-client": "file:../http-client/actions-http-client-3.0.0.tgz",
|
"@actions/http-client": "^2.0.1",
|
||||||
"@octokit/core": "^4.2.4",
|
"@octokit/core": "^3.6.0",
|
||||||
"@octokit/plugin-paginate-rest": "^6.1.2",
|
"@octokit/plugin-paginate-rest": "^2.17.0",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^7.2.3"
|
"@octokit/plugin-rest-endpoint-methods": "^5.13.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/proxy": "^1.0.1",
|
"proxy": "^1.0.2"
|
||||||
"proxy": "^2.1.1",
|
|
||||||
"undici": "^5.25.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import * as httpClient from '@actions/http-client'
|
import * as httpClient from '@actions/http-client'
|
||||||
import {OctokitOptions} from '@octokit/core/dist-types/types'
|
import {OctokitOptions} from '@octokit/core/dist-types/types'
|
||||||
import { ProxyServer, createProxy } from "proxy";
|
|
||||||
import { ProxyAgent, Agent, fetch as undiciFetch } from "undici";
|
|
||||||
|
|
||||||
export function getAuthString(
|
export function getAuthString(
|
||||||
token: string,
|
token: string,
|
||||||
@@ -22,22 +20,6 @@ export function getProxyAgent(destinationUrl: string): http.Agent {
|
|||||||
return hc.getAgent(destinationUrl)
|
return hc.getAgent(destinationUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNewProxyAgent(destinationUrl: string): ProxyAgent | Agent {
|
|
||||||
const hc = new httpClient.HttpClient()
|
|
||||||
return hc.getNewAgent(destinationUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getProxyFetchAgent(destinationUrl): any {
|
|
||||||
const httpAgent = getNewProxyAgent(destinationUrl)
|
|
||||||
const myFetch: typeof undiciFetch = (url, opts) => {
|
|
||||||
return undiciFetch(url, {
|
|
||||||
...opts,
|
|
||||||
dispatcher: httpAgent,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
return myFetch;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getApiBaseUrl(): string {
|
export function getApiBaseUrl(): string {
|
||||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const baseUrl = Utils.getApiBaseUrl()
|
|||||||
export const defaults: OctokitOptions = {
|
export const defaults: OctokitOptions = {
|
||||||
baseUrl,
|
baseUrl,
|
||||||
request: {
|
request: {
|
||||||
fetch: Utils.getProxyFetchAgent(baseUrl)
|
agent: Utils.getProxyAgent(baseUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import * as httpm from '../lib/'
|
import * as httpm from '../lib/'
|
||||||
import * as pm from '../lib/proxy'
|
import * as pm from '../lib/proxy'
|
||||||
|
import {ProxyAgent} from 'undici'
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
||||||
const proxy = require('proxy')
|
const proxy = require('proxy')
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ const _proxyUrl = 'http://127.0.0.1:8080'
|
|||||||
describe('proxy', () => {
|
describe('proxy', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Start proxy server
|
// Start proxy server
|
||||||
_proxyServer = proxy()
|
_proxyServer = proxy.createProxy()
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
const port = Number(_proxyUrl.split(':')[2])
|
const port = Number(_proxyUrl.split(':')[2])
|
||||||
_proxyServer.listen(port, () => resolve())
|
_proxyServer.listen(port, () => resolve())
|
||||||
@@ -294,6 +295,15 @@ describe('proxy', () => {
|
|||||||
expect(agent.proxyOptions.port).toBe('8080')
|
expect(agent.proxyOptions.port).toBe('8080')
|
||||||
expect(agent.proxyOptions.proxyAuth).toBe('user:password')
|
expect(agent.proxyOptions.proxyAuth).toBe('user:password')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('ProxyAgent is returned when proxy setting are provided', async () => {
|
||||||
|
process.env['https_proxy'] = 'http://127.0.0.1:8080'
|
||||||
|
const httpClient = new httpm.HttpClient()
|
||||||
|
const agent = httpClient.getAgentDispatcher('https://some-url')
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(agent)
|
||||||
|
expect(agent instanceof ProxyAgent).toBe(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function _clearVars(): void {
|
function _clearVars(): void {
|
||||||
|
|||||||
Binary file not shown.
Generated
+28
-53
@@ -1,22 +1,30 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/http-client",
|
"name": "@actions/http-client",
|
||||||
"version": "3.0.0",
|
"version": "2.2.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@actions/http-client",
|
"name": "@actions/http-client",
|
||||||
"version": "3.0.0",
|
"version": "2.2.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6",
|
||||||
|
"undici": "^5.25.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.7.1",
|
"@types/node": "20.7.1",
|
||||||
"@types/proxy": "^1.0.2",
|
"@types/proxy": "^1.0.1",
|
||||||
"@types/tunnel": "0.0.3",
|
"@types/tunnel": "0.0.3",
|
||||||
"proxy": "^2.1.1",
|
"proxy": "^2.1.1"
|
||||||
"undici": "^5.25.2"
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@fastify/busboy": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
@@ -76,18 +84,6 @@
|
|||||||
"integrity": "sha512-GFj8iVxo9onSU6BnnQvVwqvxh60UcSHJEDnIk3z4B6iOjsKSmqe+ibW0Rsz7YO7IE1HG3D3tqCNIidP46SZVdQ==",
|
"integrity": "sha512-GFj8iVxo9onSU6BnnQvVwqvxh60UcSHJEDnIk3z4B6iOjsKSmqe+ibW0Rsz7YO7IE1HG3D3tqCNIidP46SZVdQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/busboy": {
|
|
||||||
"version": "1.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
|
|
||||||
"integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"streamsearch": "^1.1.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10.16.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/camelcase": {
|
"node_modules/camelcase": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.0.0.tgz",
|
||||||
@@ -199,15 +195,6 @@
|
|||||||
"node": ">= 14"
|
"node": ">= 14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/streamsearch": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
|
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/supports-color": {
|
"node_modules/supports-color": {
|
||||||
"version": "5.5.0",
|
"version": "5.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
||||||
@@ -229,12 +216,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici": {
|
"node_modules/undici": {
|
||||||
"version": "5.25.2",
|
"version": "5.25.4",
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.25.2.tgz",
|
"resolved": "https://registry.npmjs.org/undici/-/undici-5.25.4.tgz",
|
||||||
"integrity": "sha512-tch8RbCfn1UUH1PeVCXva4V8gDpGAud/w0WubD6sHC46vYQ3KDxL+xv1A2UxK0N6jrVedutuPHxe1XIoqerwMw==",
|
"integrity": "sha512-450yJxT29qKMf3aoudzFpIciqpx6Pji3hEWaXqXmanbXF58LTAGCKxcJjxMXWu3iG+Mudgo3ZUfDB6YDFd/dAw==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"busboy": "^1.6.0"
|
"@fastify/busboy": "^2.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.0"
|
"node": ">=14.0"
|
||||||
@@ -242,6 +228,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@fastify/busboy": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ=="
|
||||||
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "20.7.1",
|
"version": "20.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.7.1.tgz",
|
||||||
@@ -293,15 +284,6 @@
|
|||||||
"integrity": "sha512-GFj8iVxo9onSU6BnnQvVwqvxh60UcSHJEDnIk3z4B6iOjsKSmqe+ibW0Rsz7YO7IE1HG3D3tqCNIidP46SZVdQ==",
|
"integrity": "sha512-GFj8iVxo9onSU6BnnQvVwqvxh60UcSHJEDnIk3z4B6iOjsKSmqe+ibW0Rsz7YO7IE1HG3D3tqCNIidP46SZVdQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"busboy": {
|
|
||||||
"version": "1.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
|
|
||||||
"integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"streamsearch": "^1.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"camelcase": {
|
"camelcase": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.0.0.tgz",
|
||||||
@@ -384,12 +366,6 @@
|
|||||||
"debug": "^4.3.4"
|
"debug": "^4.3.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"streamsearch": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"supports-color": {
|
"supports-color": {
|
||||||
"version": "5.5.0",
|
"version": "5.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
||||||
@@ -405,12 +381,11 @@
|
|||||||
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
|
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
|
||||||
},
|
},
|
||||||
"undici": {
|
"undici": {
|
||||||
"version": "5.25.2",
|
"version": "5.25.4",
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.25.2.tgz",
|
"resolved": "https://registry.npmjs.org/undici/-/undici-5.25.4.tgz",
|
||||||
"integrity": "sha512-tch8RbCfn1UUH1PeVCXva4V8gDpGAud/w0WubD6sHC46vYQ3KDxL+xv1A2UxK0N6jrVedutuPHxe1XIoqerwMw==",
|
"integrity": "sha512-450yJxT29qKMf3aoudzFpIciqpx6Pji3hEWaXqXmanbXF58LTAGCKxcJjxMXWu3iG+Mudgo3ZUfDB6YDFd/dAw==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"busboy": "^1.6.0"
|
"@fastify/busboy": "^2.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/http-client",
|
"name": "@actions/http-client",
|
||||||
"version": "3.0.0",
|
"version": "2.2.0",
|
||||||
"description": "Actions Http Client",
|
"description": "Actions Http Client",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
@@ -39,13 +39,13 @@
|
|||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.7.1",
|
"@types/node": "20.7.1",
|
||||||
"@types/proxy": "^1.0.2",
|
|
||||||
"@types/tunnel": "0.0.3",
|
"@types/tunnel": "0.0.3",
|
||||||
"proxy": "^2.1.1",
|
"proxy": "^2.1.1",
|
||||||
"undici": "^5.25.2"
|
"@types/proxy": "^1.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6",
|
||||||
|
"undici": "^5.25.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import * as ifm from './interfaces'
|
|||||||
import * as net from 'net'
|
import * as net from 'net'
|
||||||
import * as pm from './proxy'
|
import * as pm from './proxy'
|
||||||
import * as tunnel from 'tunnel'
|
import * as tunnel from 'tunnel'
|
||||||
import { ProxyAgent, Agent, fetch as undiciFetch } from "undici";
|
import {ProxyAgent} from 'undici'
|
||||||
|
|
||||||
export enum HttpCodes {
|
export enum HttpCodes {
|
||||||
OK = 200,
|
OK = 200,
|
||||||
@@ -137,9 +137,8 @@ export class HttpClient {
|
|||||||
private _allowRetries = false
|
private _allowRetries = false
|
||||||
private _maxRetries = 1
|
private _maxRetries = 1
|
||||||
private _agent: any
|
private _agent: any
|
||||||
private _newAgent: any
|
|
||||||
private _proxyAgent: any
|
private _proxyAgent: any
|
||||||
private _newProxyAgent: any
|
private _proxyAgentDispatcher: any
|
||||||
private _keepAlive = false
|
private _keepAlive = false
|
||||||
private _disposed = false
|
private _disposed = false
|
||||||
|
|
||||||
@@ -567,16 +566,15 @@ export class HttpClient {
|
|||||||
return this._getAgent(parsedUrl)
|
return this._getAgent(parsedUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
getNewAgent(serverUrl: string): ProxyAgent | Agent {
|
getAgentDispatcher(serverUrl: string): ProxyAgent | undefined {
|
||||||
const parsedUrl = new URL(serverUrl)
|
const parsedUrl = new URL(serverUrl)
|
||||||
const proxyUrl = pm.getProxyUrl(parsedUrl)
|
const proxyUrl = pm.getProxyUrl(parsedUrl)
|
||||||
const useProxy = proxyUrl && proxyUrl.hostname
|
const useProxy = proxyUrl && proxyUrl.hostname
|
||||||
if (useProxy) {
|
if (!useProxy) {
|
||||||
return this._getProxyAgent(parsedUrl)
|
return
|
||||||
}
|
|
||||||
else {
|
|
||||||
return this._getNewAgent(parsedUrl)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this._getProxyAgentDispatcher(parsedUrl, proxyUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
private _prepareRequest(
|
private _prepareRequest(
|
||||||
@@ -694,7 +692,7 @@ export class HttpClient {
|
|||||||
|
|
||||||
// if reusing agent across request and tunneling agent isn't assigned create a new agent
|
// if reusing agent across request and tunneling agent isn't assigned create a new agent
|
||||||
if (this._keepAlive && !agent) {
|
if (this._keepAlive && !agent) {
|
||||||
const options = { keepAlive: this._keepAlive, maxSockets }
|
const options = {keepAlive: this._keepAlive, maxSockets}
|
||||||
agent = usingSsl ? new https.Agent(options) : new http.Agent(options)
|
agent = usingSsl ? new https.Agent(options) : new http.Agent(options)
|
||||||
this._agent = agent
|
this._agent = agent
|
||||||
}
|
}
|
||||||
@@ -716,17 +714,11 @@ export class HttpClient {
|
|||||||
return agent
|
return agent
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getProxyAgent(parsedUrl: URL): ProxyAgent {
|
private _getProxyAgentDispatcher(parsedUrl: URL, proxyUrl: URL): ProxyAgent {
|
||||||
let proxyAgent
|
let proxyAgent
|
||||||
const proxyUrl = pm.getProxyUrl(parsedUrl)
|
|
||||||
const useProxy = proxyUrl && proxyUrl.hostname
|
|
||||||
|
|
||||||
if (this._keepAlive && useProxy) {
|
if (this._keepAlive) {
|
||||||
proxyAgent = this._newProxyAgent
|
proxyAgent = this._proxyAgentDispatcher
|
||||||
}
|
|
||||||
|
|
||||||
if (this._keepAlive && !useProxy) {
|
|
||||||
proxyAgent = this._newAgent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if agent is already assigned use that agent.
|
// if agent is already assigned use that agent.
|
||||||
@@ -735,22 +727,14 @@ export class HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const usingSsl = parsedUrl.protocol === 'https:'
|
const usingSsl = parsedUrl.protocol === 'https:'
|
||||||
let maxSockets = 100
|
proxyAgent = new ProxyAgent({
|
||||||
if (this.requestOptions) {
|
uri: proxyUrl.href,
|
||||||
maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets
|
pipelining: !this._keepAlive ? 0 : 1,
|
||||||
}
|
...((proxyUrl.username || proxyUrl.password) && {
|
||||||
|
token: `${proxyUrl.username}:${proxyUrl.password}`
|
||||||
// This is `useProxy` again, but we need to check `proxyURl` directly for TypeScripts's flow analysis.
|
|
||||||
if (proxyUrl && proxyUrl.hostname) {
|
|
||||||
proxyAgent = new ProxyAgent({
|
|
||||||
uri: proxyUrl.href,
|
|
||||||
pipelining: (!this._keepAlive ? 0 : 1),
|
|
||||||
...((proxyUrl.username || proxyUrl.password) && {
|
|
||||||
token: `${proxyUrl.username}:${proxyUrl.password}`
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
this._newProxyAgent = proxyAgent
|
})
|
||||||
}
|
this._proxyAgentDispatcher = proxyAgent
|
||||||
|
|
||||||
if (usingSsl && this._ignoreSslError) {
|
if (usingSsl && this._ignoreSslError) {
|
||||||
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
||||||
@@ -764,46 +748,6 @@ export class HttpClient {
|
|||||||
return proxyAgent
|
return proxyAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getNewAgent(parsedUrl: URL): Agent {
|
|
||||||
let agent;
|
|
||||||
|
|
||||||
if (this._keepAlive) {
|
|
||||||
agent = this._newAgent
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 (this._keepAlive && !agent) {
|
|
||||||
agent = new Agent(
|
|
||||||
{
|
|
||||||
pipelining: (!this._keepAlive ? 0 : 1),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
this._newAgent = 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> {
|
private async _performExponentialBackoff(retryNumber: number): Promise<void> {
|
||||||
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber)
|
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber)
|
||||||
const ms: number = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber)
|
const ms: number = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber)
|
||||||
@@ -886,5 +830,5 @@ export class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const lowercaseKeys = (obj: { [index: string]: any }): any =>
|
const lowercaseKeys = (obj: {[index: string]: any}): any =>
|
||||||
Object.keys(obj).reduce((c: any, k) => ((c[k.toLowerCase()] = obj[k]), c), {})
|
Object.keys(obj).reduce((c: any, k) => ((c[k.toLowerCase()] = obj[k]), c), {})
|
||||||
|
|||||||
Generated
+16
-9
@@ -93,13 +93,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.1.1",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
"deprecated": "Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ms": "^2.1.1"
|
"ms": "2.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/json-stringify-safe": {
|
"node_modules/json-stringify-safe": {
|
||||||
@@ -239,12 +246,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.1.1",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"ms": "^2.1.1"
|
"ms": "2.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"json-stringify-safe": {
|
"json-stringify-safe": {
|
||||||
|
|||||||
Reference in New Issue
Block a user