Closed xNEL99 closed 6 years ago
The agent implementation was removed in v2 as it makes more sense for socks to be fully focused on being just a socks client.
I recommend: https://www.npmjs.com/package/socks-proxy-agent as a replacement, which uses the socks library behind the scenes.
Please see the migration guide for moving from v1 -> v2: https://github.com/JoshGlazebrook/socks/blob/master/docs/migratingFromV1.md
@JoshGlazebrook I appreciate the link to socks-proxy-agent, however I wanted to use your socks library because of the proxy chaining feature which doesn't appear to be available in socks-proxy-agent.
Is there any chance you can help me setting up an agent that supports a proxy chain?
@T-vK I think it's something that could be added to socks-proxy-agent. They're using .createConnection() already, so it would just be a matter of accepting a list of proxies, and then calling .createConnectionChain() instead.
Thank you @JoshGlazebrook !
So I have tried to do that here, but I'm getting errors and I haven't been able to get a response from the socks-proxy-agent
devs.
I basically just changed SocksProxyAgent
to support an array of proxies and turned opts from SocksProxyAgentOptions
into SocksProxyAgentOptions[]
. But I can't get it to run. When super(opts);
is called, I get the following error:
This probably happens because opts is now an array of opts, but I don't understand why it's even passed to super and if I need to change the parent class or the parameter I'm passing.
Is there any chance you can help me out?
I can possibly look into it a bit this weekend
Thank you. :)
Maybe it'll be helpful for someone
export class SocksProxyAgent extends https.Agent {
private readonly proxy: SocksProxy;
public constructor(options: https.AgentOptions & { proxy: SocksProxy }) {
const { proxy, ...opts } = options;
super(opts);
this.proxy = proxy;
}
protected createConnection(
options: http.ClientRequestArgs,
callback: (err: Error | null, socket: Socket | null) => void,
): void {
const socksOpts: SocksClientOptions = {
proxy: this.proxy,
command: 'connect',
timeout: options.timeout,
destination: {
host: options.host!,
port: +options.port!,
},
};
void SocksClient.createConnection(socksOpts, (err: Error | null, info?: { socket: Socket }) => {
if (err) {
callback(err, null);
} else {
const secureSocket = super.createConnection({ ...options, socket: info?.socket });
callback(null, secureSocket);
}
});
}
}
Previous discussion on why agent was removed from here: https://github.com/JoshGlazebrook/socks/issues/23#issuecomment-354938712
Thank @JoshGlazebrook for your comment and quick answer. I read and agree with that answer.
That package has an issue with TLS. I've just offered a working solution rewritten from scratch without any dependencies. Maybe someone will be looking for such a solution.
I don't offer to add SocksProxyAgent to socks
library :)
Anyway thanks for your comment 🤝 ✌️
@korniychuk Ah, well feel free to make a PR to add this to the examples folder. I'm sure a lot of people specifically use this package for that use!
@T-vK would you kindly share your solution to this problem with me, please. I want to achieve a similar thing. Https request -> local Tor socks5 proxy -> my external socks5 proxy -> webserver.
Why does the Agent property got removed on the new update