[http] explicitly create the server listener (#183591)

## Summary

Related to https://github.com/elastic/kibana/issues/7104
Adapted from https://github.com/elastic/kibana/pull/183465

For `http2` support, we will have to change the way we configure the
HAPI server to manually provide the listener instead of passing down the
options for HAPI to create it.

This PR prepares that work, by creating the `http` or `https` (`tls`)
listener and passing it when creating the HAPI server instead of just
passing the `tls` options.

**Note:** no integration tests were added, because we already have the
right coverage for both tls and non-tls mode, so any change of behavior
introduced by the PR should be detectable by them.
This commit is contained in:
Pierre Gayvallet 2024-05-21 17:11:20 +02:00 committed by GitHub
parent 2c9a89e921
commit db316ad475
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 463 additions and 170 deletions

View file

@ -15,7 +15,7 @@ import { sampleSize } from 'lodash';
import * as Rx from 'rxjs';
import { take } from 'rxjs';
import { ByteSizeValue } from '@kbn/config-schema';
import { createServer, getListenerOptions, getServerOptions } from '@kbn/server-http-tools';
import { createServer, getServerOptions } from '@kbn/server-http-tools';
import { DevConfig, HttpConfig } from './config';
import { Log } from './log';
@ -67,8 +67,7 @@ export class BasePathProxyServer {
public async start(options: BasePathProxyServerOptions) {
const serverOptions = getServerOptions(this.httpConfig);
const listenerOptions = getListenerOptions(this.httpConfig);
this.server = createServer(serverOptions, listenerOptions);
this.server = createServer(serverOptions);
// Register hapi plugin that adds proxying functionality. It can be configured
// through the route configuration object (see { handler: { proxy: ... } }).

View file

@ -10,12 +10,7 @@ import { Server } from '@hapi/hapi';
import { EMPTY } from 'rxjs';
import moment from 'moment';
import supertest from 'supertest';
import {
getServerOptions,
getListenerOptions,
createServer,
IHttpConfig,
} from '@kbn/server-http-tools';
import { getServerOptions, createServer, type IHttpConfig } from '@kbn/server-http-tools';
import { ByteSizeValue } from '@kbn/config-schema';
import { BasePathProxyServer, BasePathProxyServerOptions } from '../base_path_proxy_server';
@ -51,8 +46,7 @@ describe('BasePathProxyServer', () => {
};
const serverOptions = getServerOptions(config);
const listenerOptions = getListenerOptions(config);
server = createServer(serverOptions, listenerOptions);
server = createServer(serverOptions);
// setup and start the proxy server
const proxyConfig: IHttpConfig = { ...config, port: 10013 };
@ -276,8 +270,7 @@ describe('BasePathProxyServer', () => {
} as IHttpConfig;
const serverOptions = getServerOptions(configWithBasePath);
const listenerOptions = getListenerOptions(configWithBasePath);
server = createServer(serverOptions, listenerOptions);
server = createServer(serverOptions);
server.route({
method: 'GET',