From bbea59939ebd9870b5bffd070c4be6803c36369a Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Tue, 11 Aug 2020 11:53:23 +0200 Subject: [PATCH] feat: add http2 option (#6957) --- docs/usage/configuration-options.md | 4 ++++ lib/config/definitions.ts | 10 +++++++++ lib/types/host-rules.ts | 1 + lib/util/http/host-rules.spec.ts | 34 +++++++++++++++++++++++++++++ lib/util/http/host-rules.ts | 5 +++++ 5 files changed, 54 insertions(+) diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 87c56cbc7b..3bb7804377 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -572,6 +572,10 @@ Renovate does not do a "longest match" algorithm to pick between multiple matchi If you have any uncertainty about exactly which hosts a service uses, then it can be more reliable to use `domainName` instead of `hostName` or `baseUrl`. e.g. configure `"hostName": "docker.io"` to cover both `index.docker.io` and `auth.docker.io` and any other host that's in use. +### enableHttp2 + +Enable got [http2](https://github.com/sindresorhus/got/blob/v11.5.2/readme.md#http2) support. + ### hostName ### hostType diff --git a/lib/config/definitions.ts b/lib/config/definitions.ts index 941a8376c0..70e2c189b1 100644 --- a/lib/config/definitions.ts +++ b/lib/config/definitions.ts @@ -1666,6 +1666,16 @@ const options: RenovateOptions[] = [ cli: false, env: false, }, + { + name: 'enableHttp2', + description: 'Enable got http2 support.', + type: 'boolean', + stage: 'repository', + parent: 'hostRules', + default: false, + cli: false, + env: false, + }, { name: 'prBodyDefinitions', description: 'Table column definitions for use in PR tables', diff --git a/lib/types/host-rules.ts b/lib/types/host-rules.ts index 58ed1867d8..0f2b517b50 100644 --- a/lib/types/host-rules.ts +++ b/lib/types/host-rules.ts @@ -16,4 +16,5 @@ export interface HostRule { abortOnError?: boolean; abortIgnoreStatusCodes?: number[]; enabled?: boolean; + enableHttp2?: boolean; } diff --git a/lib/util/http/host-rules.spec.ts b/lib/util/http/host-rules.spec.ts index 1651de3b91..666ae6180a 100644 --- a/lib/util/http/host-rules.spec.ts +++ b/lib/util/http/host-rules.spec.ts @@ -4,11 +4,14 @@ import { PLATFORM_TYPE_GITEA, PLATFORM_TYPE_GITHUB, } from '../../constants/platforms'; +import { bootstrap } from '../../proxy'; import * as hostRules from '../host-rules'; import { applyHostRules } from './host-rules'; const url = 'https://github.com'; +jest.mock('global-agent'); + describe(getName(__filename), () => { const options = { hostType: PLATFORM_TYPE_GITHUB, @@ -17,6 +20,8 @@ describe(getName(__filename), () => { // reset module jest.resetAllMocks(); + delete process.env.HTTP_PROXY; + // clean up hostRules hostRules.clear(); hostRules.add({ @@ -32,6 +37,10 @@ describe(getName(__filename), () => { httpMock.setup(); }); + afterEach(() => { + delete process.env.HTTP_PROXY; + }); + it('adds token', () => { expect(applyHostRules(url, { ...options })).toMatchInlineSnapshot(` Object { @@ -61,4 +70,29 @@ describe(getName(__filename), () => { } `); }); + + it('uses http2', () => { + hostRules.add({ enableHttp2: true }); + expect(applyHostRules(url, { ...options, token: 'xxx' })) + .toMatchInlineSnapshot(` + Object { + "hostType": "github", + "http2": true, + "token": "xxx", + } + `); + }); + + it('disables http2', () => { + process.env.HTTP_PROXY = 'http://proxy'; + bootstrap(); + hostRules.add({ enableHttp2: true }); + expect(applyHostRules(url, { ...options, token: 'xxx' })) + .toMatchInlineSnapshot(` + Object { + "hostType": "github", + "token": "xxx", + } + `); + }); }); diff --git a/lib/util/http/host-rules.ts b/lib/util/http/host-rules.ts index f579a84dae..1146fe5a67 100644 --- a/lib/util/http/host-rules.ts +++ b/lib/util/http/host-rules.ts @@ -1,4 +1,5 @@ import { logger } from '../../logger'; +import { hasProxy } from '../../proxy'; import * as hostRules from '../host-rules'; import { GotOptions } from './types'; @@ -30,5 +31,9 @@ export function applyHostRules(url: string, inOptions: GotOptions): GotOptions { options[param] = foundRules[param]; } }); + + if (!hasProxy() && foundRules.enableHttp2 === true) { + options.http2 = true; + } return options; } -- GitLab