mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 06:26:26 +00:00
feat: http keepalives (#17582)
This commit is contained in:
parent
22d0d347e5
commit
9bc8b05af3
8 changed files with 42 additions and 1 deletions
|
@ -1183,6 +1183,10 @@ Example:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### keepalive
|
||||||
|
|
||||||
|
If enabled, this allows a single TCP connection to remain open for multiple HTTP(S) requests/responses.
|
||||||
|
|
||||||
### matchHost
|
### matchHost
|
||||||
|
|
||||||
This can be a base URL (e.g. `https://api.github.com`) or a hostname like `github.com` or `api.github.com`.
|
This can be a base URL (e.g. `https://api.github.com`) or a hostname like `github.com` or `api.github.com`.
|
||||||
|
|
|
@ -2115,6 +2115,17 @@ const options: RenovateOptions[] = [
|
||||||
env: false,
|
env: false,
|
||||||
experimental: true,
|
experimental: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'keepalive',
|
||||||
|
description: 'Enable http keepalives for hosts',
|
||||||
|
type: 'boolean',
|
||||||
|
stage: 'repository',
|
||||||
|
parent: 'hostRules',
|
||||||
|
default: false,
|
||||||
|
cli: false,
|
||||||
|
env: false,
|
||||||
|
experimental: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'prBodyDefinitions',
|
name: 'prBodyDefinitions',
|
||||||
description: 'Table column definitions for use in PR tables.',
|
description: 'Table column definitions for use in PR tables.',
|
||||||
|
|
|
@ -12,6 +12,7 @@ export interface HostRuleSearchResult {
|
||||||
concurrentRequestLimit?: number;
|
concurrentRequestLimit?: number;
|
||||||
|
|
||||||
dnsCache?: boolean;
|
dnsCache?: boolean;
|
||||||
|
keepalive?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HostRule extends HostRuleSearchResult {
|
export interface HostRule extends HostRuleSearchResult {
|
||||||
|
|
|
@ -119,6 +119,13 @@ describe('util/http/host-rules', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses http keepalives', () => {
|
||||||
|
hostRules.add({ keepalive: true });
|
||||||
|
expect(
|
||||||
|
applyHostRules(url, { ...options, token: 'xxx' }).agent
|
||||||
|
).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('disables http2', () => {
|
it('disables http2', () => {
|
||||||
process.env.HTTP_PROXY = 'http://proxy';
|
process.env.HTTP_PROXY = 'http://proxy';
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { hasProxy } from '../../proxy';
|
||||||
import type { HostRule } from '../../types';
|
import type { HostRule } from '../../types';
|
||||||
import * as hostRules from '../host-rules';
|
import * as hostRules from '../host-rules';
|
||||||
import { dnsLookup } from './dns';
|
import { dnsLookup } from './dns';
|
||||||
|
import { keepaliveAgents } from './keepalive';
|
||||||
import type { GotOptions } from './types';
|
import type { GotOptions } from './types';
|
||||||
|
|
||||||
export function findMatchingRules(options: GotOptions, url: string): HostRule {
|
export function findMatchingRules(options: GotOptions, url: string): HostRule {
|
||||||
|
@ -109,6 +110,10 @@ export function applyHostRules(url: string, inOptions: GotOptions): GotOptions {
|
||||||
options.lookup = dnsLookup;
|
options.lookup = dnsLookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (foundRules.keepalive) {
|
||||||
|
options.agent = keepaliveAgents;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasProxy() && foundRules.enableHttp2 === true) {
|
if (!hasProxy() && foundRules.enableHttp2 === true) {
|
||||||
options.http2 = true;
|
options.http2 = true;
|
||||||
}
|
}
|
||||||
|
|
12
lib/util/http/keepalive.ts
Normal file
12
lib/util/http/keepalive.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import Agent, { HttpsAgent } from 'agentkeepalive';
|
||||||
|
import type { Agents } from 'got';
|
||||||
|
|
||||||
|
const http = new Agent();
|
||||||
|
const https = new HttpsAgent();
|
||||||
|
|
||||||
|
const keepaliveAgents: Agents = {
|
||||||
|
http,
|
||||||
|
https,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { keepaliveAgents };
|
|
@ -149,6 +149,7 @@
|
||||||
"@types/tmp": "0.2.3",
|
"@types/tmp": "0.2.3",
|
||||||
"@yarnpkg/core": "3.2.4",
|
"@yarnpkg/core": "3.2.4",
|
||||||
"@yarnpkg/parsers": "2.5.1",
|
"@yarnpkg/parsers": "2.5.1",
|
||||||
|
"agentkeepalive": "4.2.1",
|
||||||
"auth-header": "1.0.0",
|
"auth-header": "1.0.0",
|
||||||
"azure-devops-node-api": "11.2.0",
|
"azure-devops-node-api": "11.2.0",
|
||||||
"bunyan": "1.8.15",
|
"bunyan": "1.8.15",
|
||||||
|
|
|
@ -3172,7 +3172,7 @@ agent-base@6, agent-base@^6.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
debug "4"
|
debug "4"
|
||||||
|
|
||||||
agentkeepalive@^4.2.1:
|
agentkeepalive@4.2.1, agentkeepalive@^4.2.1:
|
||||||
version "4.2.1"
|
version "4.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-4.2.1.tgz#a7975cbb9f83b367f06c90cc51ff28fe7d499717"
|
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-4.2.1.tgz#a7975cbb9f83b367f06c90cc51ff28fe7d499717"
|
||||||
integrity sha512-Zn4cw2NEqd+9fiSVWMscnjyQ1a8Yfoc5oBajLeo5w+YBHgDUcEBY2hS4YpTz6iN5f/2zQiktcuM6tS8x1p9dpA==
|
integrity sha512-Zn4cw2NEqd+9fiSVWMscnjyQ1a8Yfoc5oBajLeo5w+YBHgDUcEBY2hS4YpTz6iN5f/2zQiktcuM6tS8x1p9dpA==
|
||||||
|
|
Loading…
Reference in a new issue