Skip to content

Commit

Permalink
Allow Ip addresses when using async ip resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jan 15, 2014
1 parent 4b17837 commit 090a3df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/fetch.js
Expand Up @@ -6,7 +6,8 @@ var http = require("http"),
dns = require('dns'),
Stream = require("stream").Stream,
CookieJar = require("./cookiejar").CookieJar,
encodinglib = require("encoding");
encodinglib = require("encoding"),
net = require("net");

exports.FetchStream = FetchStream;
exports.CookieJar = CookieJar;
Expand Down Expand Up @@ -233,20 +234,24 @@ FetchStream.prototype.runStream = function(url){
}

if (this.options.asyncDnsLoookup) {
var dnsCallback = (function (err, adresses){
var dnsCallback = (function (err, addresses){
if (err) {
this.emit("error", err);
return;
}

url_data.urloptions.headers['host'] = url_data.urloptions.hostname || url_data.urloptions.host;
url_data.urloptions.hostname = adresses[0];
url_data.urloptions.hostname = addresses[0];
url_data.urloptions.host = url_data.urloptions.headers['host'] + (url_data.urloptions.port? ':' + url_data.urloptions.port: '');

this._runStream(url_data, url);
}).bind(this);

dns.resolve4(url_data.urloptions.host, dnsCallback);
if(net.isIP(url_data.urloptions.host)){
dnsCallback(null, [url_data.urloptions.host]);
}else{
dns.resolve4(url_data.urloptions.host, dnsCallback);
}
} else {
this._runStream(url_data, url);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "fetch",
"description": "Fetch URL contents",
"version": "0.3.5",
"version": "0.3.6",
"author": "Andris Reinman",
"maintainers": [
"andris <andris@node.ee>"
Expand Down

0 comments on commit 090a3df

Please sign in to comment.