undici icon indicating copy to clipboard operation
undici copied to clipboard

Implement localAddress in Agent

Open mcollina opened this issue 3 years ago • 3 comments

Originally posted by @RemoQuality in https://github.com/nodejs/undici/discussions/1577:

I was trying to use undici request with option to select which IP address should be used to request but without any success.

Example how I am doing it with AXIOS: await axios(url, { httpsAgent: new https.Agent({ localAddress: "XXX.XXX.XXX.XXX", keepAlive: true, keepAliveMsecs: 30000 }) }) .then(res => {}) any possibilities of that with undici?

mcollina avatar Jul 26 '22 11:07 mcollina

This will be a good feature to add!

mcollina avatar Jul 26 '22 11:07 mcollina

@mcollina I would love to work on this, any suggestions as to where I should start looking to implement this?

My guess is, inside agent.js the Agent expects a factory that either returns a Client or a Pool https://github.com/nodejs/undici/blob/main/lib/agent.js#L49

And inside the client.js this is where the IP resolution happens i guess? https://github.com/nodejs/undici/blob/03cfc4be563e19fb55ec33177dcf45c45fee828c/lib/client.js#L997

Or am I just digging the wrong part of the codebase :smile:

sidwebworks avatar Aug 27 '22 12:08 sidwebworks

I think this should be in client.js.

mcollina avatar Aug 27 '22 15:08 mcollina

Can be closed with #1659?

metcoder95 avatar Oct 19 '22 06:10 metcoder95