fetch-h2
fetch-h2 copied to clipboard
Is there any way to specify localAdress?
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?
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.
OK thanks! I will report the results
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.
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
Did you fix this issue @grantila ? I really want to use my local address and ipv6 for http2 request, thank you