Created
August 17, 2012 20:47
-
-
Save lerouxb/3382480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| }); | |
| } |
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
On version 0.8.7 the http case works and the https case fails. Both those urls point to the same image.