feat(core): Add backendProtocol option to support HTTP/2 client sessions alongside HTTP/1. This update enhances NetworkProxy's core functionality by integrating HTTP/2 support in server creation and request handling, while updating plugin exports and documentation accordingly.
This commit is contained in:
@ -16,8 +16,8 @@ export class NetworkProxy implements IMetricsTracker {
|
||||
public options: INetworkProxyOptions;
|
||||
public proxyConfigs: IReverseProxyConfig[] = [];
|
||||
|
||||
// Server instances
|
||||
public httpsServer: plugins.https.Server;
|
||||
// Server instances (HTTP/2 with HTTP/1 fallback)
|
||||
public httpsServer: any;
|
||||
|
||||
// Core components
|
||||
private certificateManager: CertificateManager;
|
||||
@ -66,6 +66,8 @@ export class NetworkProxy implements IMetricsTracker {
|
||||
connectionPoolSize: optionsArg.connectionPoolSize || 50,
|
||||
portProxyIntegration: optionsArg.portProxyIntegration || false,
|
||||
useExternalPort80Handler: optionsArg.useExternalPort80Handler || false,
|
||||
// Backend protocol (http1 or http2)
|
||||
backendProtocol: optionsArg.backendProtocol || 'http1',
|
||||
// Default ACME options
|
||||
acme: {
|
||||
enabled: optionsArg.acme?.enabled || false,
|
||||
@ -185,33 +187,35 @@ export class NetworkProxy implements IMetricsTracker {
|
||||
await this.certificateManager.initializePort80Handler();
|
||||
}
|
||||
|
||||
// Create the HTTPS server
|
||||
this.httpsServer = plugins.https.createServer(
|
||||
// Create HTTP/2 server with HTTP/1 fallback
|
||||
this.httpsServer = plugins.http2.createSecureServer(
|
||||
{
|
||||
key: this.certificateManager.getDefaultCertificates().key,
|
||||
cert: this.certificateManager.getDefaultCertificates().cert,
|
||||
SNICallback: (domain, cb) => this.certificateManager.handleSNI(domain, cb)
|
||||
},
|
||||
(req, res) => this.requestHandler.handleRequest(req, res)
|
||||
allowHTTP1: true,
|
||||
ALPNProtocols: ['h2', 'http/1.1']
|
||||
}
|
||||
);
|
||||
|
||||
// Configure server timeouts
|
||||
this.httpsServer.keepAliveTimeout = this.options.keepAliveTimeout;
|
||||
this.httpsServer.headersTimeout = this.options.headersTimeout;
|
||||
|
||||
// Setup connection tracking
|
||||
// Track raw TCP connections for metrics and limits
|
||||
this.setupConnectionTracking();
|
||||
|
||||
// Share HTTPS server with certificate manager
|
||||
|
||||
// Handle incoming HTTP/2 streams
|
||||
this.httpsServer.on('stream', (stream: any, headers: any) => {
|
||||
this.requestHandler.handleHttp2(stream, headers);
|
||||
});
|
||||
// Handle HTTP/1.x fallback requests
|
||||
this.httpsServer.on('request', (req: any, res: any) => {
|
||||
this.requestHandler.handleRequest(req, res);
|
||||
});
|
||||
|
||||
// Share server with certificate manager for dynamic contexts
|
||||
this.certificateManager.setHttpsServer(this.httpsServer);
|
||||
|
||||
// Setup WebSocket support
|
||||
// Setup WebSocket support on HTTP/1 fallback
|
||||
this.webSocketHandler.initialize(this.httpsServer);
|
||||
|
||||
// Start metrics collection
|
||||
// Start metrics logging
|
||||
this.setupMetricsCollection();
|
||||
|
||||
// Setup connection pool cleanup interval
|
||||
// Start periodic connection pool cleanup
|
||||
this.connectionPoolCleanupInterval = this.connectionPool.setupPeriodicCleanup();
|
||||
|
||||
// Start the server
|
||||
|
Reference in New Issue
Block a user