Add Storage-Type and Response-Time header, indicating how the skin was retrieved and time it took to process the request respectively

This commit is contained in:
Jake 2014-10-19 20:43:27 -05:00
parent 1269a9befa
commit 3762a3f8bc

View File

@ -10,6 +10,7 @@ router.get('/:uuid/:size?', function(req, res) {
var uuid = req.param('uuid'); var uuid = req.param('uuid');
var size = req.param('size') || 180; var size = req.param('size') || 180;
var def = req.query.default; var def = req.query.default;
var start = new Date();
// Prevent app from crashing/freezing // Prevent app from crashing/freezing
if (size <= 0 || size > 512) size = 180; if (size <= 0 || size > 512) size = 180;
if (valid_uuid.test(uuid)) { if (valid_uuid.test(uuid)) {
@ -18,7 +19,8 @@ router.get('/:uuid/:size?', function(req, res) {
console.log('found ' + filename); console.log('found ' + filename);
skins.resize_img("skins/" + filename, size, function(data) { skins.resize_img("skins/" + filename, size, function(data) {
// tell browser to cache image locally for 10 minutes // tell browser to cache image locally for 10 minutes
res.writeHead(200, {'Content-Type': 'image/png', 'Cache-Control': 'max-age=600, public'}); var end = new Date() - start;
res.writeHead(200, {'Content-Type': 'image/png', 'Cache-Control': 'max-age=600, public', 'Response-Time': end, 'Storage-Type': 'local'});
res.end(data); res.end(data);
}); });
} else { } else {
@ -31,7 +33,8 @@ router.get('/:uuid/:size?', function(req, res) {
console.log('got skin'); console.log('got skin');
skins.resize_img("skins/" + filename, size, function(data) { skins.resize_img("skins/" + filename, size, function(data) {
// tell browser to cache image locally for 10 minutes // tell browser to cache image locally for 10 minutes
res.writeHead(200, {'Content-Type': 'image/png', 'Cache-Control': 'max-age=600, public'}); var end = new Date() - start;
res.writeHead(200, {'Content-Type': 'image/png', 'Cache-Control': 'max-age=600, public', 'Response-Time': end, 'Storage-Type': 'downloaded'});
res.end(data); res.end(data);
}); });
}); });
@ -41,20 +44,21 @@ router.get('/:uuid/:size?', function(req, res) {
case "alex": case "alex":
skins.resize_img("public/images/alex.png", size, function(data) { skins.resize_img("public/images/alex.png", size, function(data) {
// tell browser to cache image locally for 10 minutes // tell browser to cache image locally for 10 minutes
res.writeHead(404, {'Content-Type': 'image/png', 'Cache-Control': 'max-age=600, public'}); var end = new Date() - start;
res.writeHead(404, {'Content-Type': 'image/png', 'Cache-Control': 'max-age=600, public', 'Response-Time': end, 'Storage-Type': 'local'});
res.end(data); res.end(data);
}); });
break; break;
case "steve": case "steve":
skins.resize_img("public/images/steve.png", size, function(data) { skins.resize_img("public/images/steve.png", size, function(data) {
// tell browser to cache image locally for 10 minutes // tell browser to cache image locally for 10 minutes
res.writeHead(404, {'Content-Type': 'image/png', 'Cache-Control': 'max-age=600, public'}); var end = new Date() - start;
res.writeHead(404, {'Content-Type': 'image/png', 'Cache-Control': 'max-age=600, public', 'Response-Time': end, 'Storage-Type': 'local'});
res.end(data); res.end(data);
}); });
break; break;
default: default:
res.status(404) res.status(404).send('404 Not found');
.send('404 Not found');
break; break;
} }
} }