Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to specify localAdress? #51

Open
gnostis opened this issue Jul 2, 2019 · 5 comments
Open

Is there any way to specify localAdress? #51

gnostis opened this issue Jul 2, 2019 · 5 comments

Comments

@gnostis
Copy link

gnostis commented Jul 2, 2019

It would be great if you could specify the network interface in the options of each instance. Similar to Node localAddress. But maybe I did not notice and there is a way to do this?

@grantila
Copy link
Owner

grantila commented Jul 2, 2019

You can do this per-context using the session option.

So, if you want this globally for your app, before doing any fetch call, set it up using e.g.:

const { setup, fetch } = require( "fetch-h2" );
setup( { session: { localAddress: "1.2.3.4" } } );
fetch( ... ); // Bound to 1.2.3.4

or you create a new context where fetch requests are explicitly bound to the address:

const { context, fetch } = require( "fetch-h2" );
const { fetch: fetch1234 } = context( { session: { localAddress: "1.2.3.4" } } );
fetch( ... ); // Unspecified interface
fetch1234( ... ); // Bound to 1.2.3.4

I haven't tested this exact usage, please let me know if it works for you. I'll leave this open.

@gnostis
Copy link
Author

gnostis commented Jul 3, 2019

OK thanks! I will report the results

@gnostis
Copy link
Author

gnostis commented Jul 4, 2019

Does not work in both cases. Per context or via setup. Ignores and uses the route with the lowest metric. Tested on win64/node 12.2.0, lan, wlan and usb modem interfaces. Simple code with requests to server responding with external IP. I don't see localAddress option mentioned in node http2.connect options, only in http.request options.

@grantila
Copy link
Owner

I think it might work over https, but these properties aren't forwarded for plain http now that I look at it. I'll fix this as soon as I'm done with a bigger issue - #39

@duongvanba
Copy link

Did you fix this issue @grantila ?
I really want to use my local address and ipv6 for http2 request, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants