start fixing tests

This commit is contained in:
Juergen Kunz
2025-06-06 07:40:59 +00:00
parent 18d79ac7e1
commit b9be6533ae
15 changed files with 330 additions and 477 deletions

View File

@ -3,6 +3,7 @@ import { HttpProxy } from '../http-proxy/index.js';
import { setupBidirectionalForwarding } from '../../core/utils/socket-utils.js';
import type { IConnectionRecord, ISmartProxyOptions } from './models/interfaces.js';
import type { IRouteConfig } from './models/route-types.js';
import { WrappedSocket } from '../../core/models/wrapped-socket.js';
export class HttpProxyBridge {
private httpProxy: HttpProxy | null = null;
@ -98,7 +99,7 @@ export class HttpProxyBridge {
*/
public async forwardToHttpProxy(
connectionId: string,
socket: plugins.net.Socket,
socket: plugins.net.Socket | WrappedSocket,
record: IConnectionRecord,
initialChunk: Buffer,
httpProxyPort: number,
@ -125,7 +126,10 @@ export class HttpProxyBridge {
}
// Use centralized bidirectional forwarding
setupBidirectionalForwarding(socket, proxySocket, {
// Extract underlying socket if it's a WrappedSocket
const underlyingSocket = socket instanceof WrappedSocket ? socket.socket : socket;
setupBidirectionalForwarding(underlyingSocket, proxySocket, {
onClientData: (chunk) => {
// Update stats if needed
if (record) {

View File

@ -12,6 +12,7 @@ import { TimeoutManager } from './timeout-manager.js';
import { SharedRouteManager as RouteManager } from '../../core/routing/route-manager.js';
import { cleanupSocket, createIndependentSocketHandlers, setupSocketHandlers, createSocketWithErrorHandler, setupBidirectionalForwarding } from '../../core/utils/socket-utils.js';
import { WrappedSocket } from '../../core/models/wrapped-socket.js';
import { getUnderlyingSocket } from '../../core/models/socket-types.js';
/**
* Handles new connection processing and setup logic with support for route-based configuration
@ -192,7 +193,7 @@ export class RouteConnectionHandler {
// If no routes require TLS handling and it's not port 443, route immediately
if (!needsTlsHandling && localPort !== 443) {
// Extract underlying socket for socket-utils functions
const underlyingSocket = socket instanceof WrappedSocket ? socket.socket : socket;
const underlyingSocket = getUnderlyingSocket(socket);
// Set up proper socket handlers for immediate routing
setupSocketHandlers(
underlyingSocket,
@ -222,7 +223,7 @@ export class RouteConnectionHandler {
);
// Route immediately for non-TLS connections
this.routeConnection(underlyingSocket, record, '', undefined);
this.routeConnection(socket, record, '', undefined);
return;
}
@ -379,8 +380,7 @@ export class RouteConnectionHandler {
}
// Find the appropriate route for this connection
const underlyingSocket = socket instanceof WrappedSocket ? socket.socket : socket;
this.routeConnection(underlyingSocket, record, serverName, chunk);
this.routeConnection(socket, record, serverName, chunk);
});
}
@ -388,7 +388,7 @@ export class RouteConnectionHandler {
* Route the connection based on match criteria
*/
private routeConnection(
socket: plugins.net.Socket,
socket: plugins.net.Socket | WrappedSocket,
record: IConnectionRecord,
serverName: string,
initialChunk?: Buffer
@ -576,7 +576,7 @@ export class RouteConnectionHandler {
* Handle a forward action for a route
*/
private handleForwardAction(
socket: plugins.net.Socket,
socket: plugins.net.Socket | WrappedSocket,
record: IConnectionRecord,
route: IRouteConfig,
initialChunk?: Buffer
@ -893,7 +893,7 @@ export class RouteConnectionHandler {
* Handle a socket-handler action for a route
*/
private async handleSocketHandlerAction(
socket: plugins.net.Socket,
socket: plugins.net.Socket | WrappedSocket,
record: IConnectionRecord,
route: IRouteConfig,
initialChunk?: Buffer
@ -957,8 +957,9 @@ export class RouteConnectionHandler {
});
try {
// Call the handler with socket AND context
const result = route.action.socketHandler(socket, routeContext);
// Call the handler with the appropriate socket (extract underlying if needed)
const handlerSocket = getUnderlyingSocket(socket);
const result = route.action.socketHandler(handlerSocket, routeContext);
// Handle async handlers properly
if (result instanceof Promise) {
@ -1012,7 +1013,7 @@ export class RouteConnectionHandler {
* Sets up a direct connection to the target
*/
private setupDirectConnection(
socket: plugins.net.Socket,
socket: plugins.net.Socket | WrappedSocket,
record: IConnectionRecord,
serverName?: string,
initialChunk?: Buffer,
@ -1162,7 +1163,10 @@ export class RouteConnectionHandler {
}
// Use centralized bidirectional forwarding setup
setupBidirectionalForwarding(socket, targetSocket, {
// Extract underlying sockets for socket-utils functions
const incomingSocket = getUnderlyingSocket(socket);
setupBidirectionalForwarding(incomingSocket, targetSocket, {
onClientData: (chunk) => {
record.bytesReceived += chunk.length;
this.timeoutManager.updateActivity(record);