BREAKING CHANGE(smartproxy): Remove legacy migration utilities and deprecated forwarding helpers; consolidate route utilities, streamline interface definitions, and normalize IPv6-mapped IPv4 addresses

This commit is contained in:
2025-05-15 08:56:27 +00:00
parent aa1194ba5d
commit ac3a888453
18 changed files with 459 additions and 458 deletions

View File

@ -55,17 +55,37 @@ export abstract class ForwardingHandler extends plugins.EventEmitter implements
const randomIndex = Math.floor(Math.random() * target.host.length);
return {
host: target.host[randomIndex],
port: target.port
port: this.resolvePort(target.port)
};
}
// Single host
return {
host: target.host,
port: target.port
port: this.resolvePort(target.port)
};
}
/**
* Resolves a port value, handling 'preserve' and function ports
*/
protected resolvePort(port: number | 'preserve' | ((ctx: any) => number)): number {
if (typeof port === 'function') {
try {
// Create a minimal context for the function
const ctx = { port: 80 }; // Default port for minimal context
return port(ctx);
} catch (err) {
console.error('Error resolving port function:', err);
return 80; // Default fallback port
}
} else if (port === 'preserve') {
return 80; // Default port for 'preserve' in base handler
} else {
return port;
}
}
/**
* Redirect an HTTP request to HTTPS
* @param req The HTTP request