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

Question : How to force IPv4 #444

Closed
dparmar74 opened this issue Sep 9, 2016 · 4 comments
Closed

Question : How to force IPv4 #444

dparmar74 opened this issue Sep 9, 2016 · 4 comments

Comments

@dparmar74
Copy link

Core "Http" module has a way to force IPv4 by specifying "family" option. See example below. How would I achieve this with "axios"?

var http = require('http');
var options = {
family: 4,
host: 'www.google.com',
path: '/index.html'
}

http.get(options, (res) => {
console.log(Got response: ${res.statusCode});
// consume response body
res.resume();
}).on('error', (e) => {
console.log(Got error: ${e.message});
});

@nickuraltsev
Copy link
Contributor

nickuraltsev commented Sep 12, 2016

axios does not support the family option directly, but you can use a custom agent to achieve this as follows:

var http = require('http');
var agent = new http.Agent({ family: 4 });
axios.get('http://www.google.com/', { httpAgent: agent }); // Note: use httpsAgent for HTTPS

You can also set the agent at the instance level:

var instance = axios.create({ httpAgent: agent });
instance.get('http://www.google.com/');

or at the global level:

axios.defaults.httpAgent = agent;

Hope this helps!

@rubennorte
Copy link
Member

Mind that agent option has become httpAgent and httpsAgent in 0.14.0

@nickuraltsev
Copy link
Contributor

@rubennorte Thank you! I've updated my comment.

@dparmar74
Copy link
Author

Thank you for the suggestions. It worked with 0.12.0 (agent=agent) version but for 0.14.0 (httpAgent=agent) I'm getting ETIMEDOUT error. My test case involves making a http call to one of our micro service deployed on AWS EC2. Just wondering why it doesn't work with 0.14.0 version

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

No branches or pull requests

3 participants