Merge pull request #4367 from jaswilli/issue-4277

Timeout after two seconds on gravatar lookup.
This commit is contained in:
Hannah Wolfe 2014-11-01 11:00:32 +00:00
commit 055d3a7b75
2 changed files with 9 additions and 7 deletions

View File

@ -3,9 +3,9 @@ var _ = require('lodash'),
errors = require('../errors'),
bcrypt = require('bcryptjs'),
ghostBookshelf = require('./base'),
http = require('http'),
crypto = require('crypto'),
validator = require('validator'),
request = require('request'),
validation = require('../data/validation'),
config = require('../config'),
@ -845,14 +845,16 @@ User = ghostBookshelf.Model.extend({
resolve(userData);
}
http.get('http:' + gravatarUrl, function (res) {
if (res.statusCode !== 404) {
request({url: gravatarUrl, timeout: 2000}, function (err, response) {
if (err) {
// just resolve with no image url
resolve(userData);
}
if (response.statusCode !== 404) {
userData.image = gravatarUrl;
}
resolve(userData);
}).on('error', function () {
// Error making request just continue.
resolve(userData);
});
});

View File

@ -56,6 +56,7 @@
"passport": "0.2.0",
"passport-http-bearer": "1.0.1",
"passport-oauth2-client-password": "0.1.1",
"request": "2.47.0",
"rss": "1.0.0",
"semver": "2.2.1",
"showdown": "https://github.com/ErisDS/showdown/archive/v0.3.2-ghost.tar.gz",
@ -94,7 +95,6 @@
"matchdep": "~0.3.0",
"mocha": "~1.21.4",
"nock": "0.47.0",
"request": "~2.42.0",
"require-dir": "~0.1.0",
"rewire": "~2.1.0",
"should": "~4.0.4",