Skip to content

Instantly share code, notes, and snippets.

@lerouxb
Created August 17, 2012 20:47
Show Gist options
  • Save lerouxb/3382480 to your computer and use it in GitHub Desktop.
Save lerouxb/3382480 to your computer and use it in GitHub Desktop.
var urlmod = require('url');
var http = require('http');
var https = require('https');
var gm = require('gm');
var TIMEOUT = 10000;
function identify(url, callback) {
var parsed = urlmod.parse(url);
var get;
console.log(parsed.protocol);
if (parsed.protocol == 'https:') {
console.log("USING HTTPS");
get = https.get;
} else {
console.log("USING HTTP");
get = http.get;
}
var req = get(parsed, function(res) {
var image = gm(res);
image.identify(callback);
});
req.on('error', function(err) {
console.error(err);
callback(err);
});
req.setTimeout(TIMEOUT, function() {
req.abort();
console.log("timeout");
callback({name: "Timeout"});
});
}
if (!module.parent) {
var httpURL = "http://www.google.co.uk/images/srpr/logo3w.png";
var httpsURL = "https://www.google.co.uk/images/srpr/logo3w.png";
identify(httpURL, function(err, features) {
console.log(httpURL, err, features);
console.log();
});
identify(httpsURL, function(err, features) {
console.log(httpsURL, err, features);
console.log();
});
}
@lerouxb
Copy link
Author

lerouxb commented Aug 17, 2012

On version 0.8.7 the http case works and the https case fails. Both those urls point to the same image.

@lerouxb
Copy link
Author

lerouxb commented Aug 18, 2012

Ok so the problem is actually that https.get doesn't take a url string and you have to send it the parsed url (separate host and path). See nodejs/node-v0.x-archive#3882

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment