respond 304 on server error, fixes #135

This commit is contained in:
jomo 2016-01-20 01:50:30 +01:00
parent 9ccb0151bc
commit e7242ce773
2 changed files with 14 additions and 1 deletions

View File

@ -68,7 +68,8 @@ module.exports = function(request, response, result) {
// handle etag caching // handle etag caching
var incoming_etag = request.headers["if-none-match"]; var incoming_etag = request.headers["if-none-match"];
if (incoming_etag && incoming_etag === etag) { // also respond with 304 on server error (use client's version)
if (incoming_etag && (incoming_etag === etag || result.status === -1)) {
response.writeHead(304, headers); response.writeHead(304, headers);
response.end(); response.end();
return; return;

View File

@ -791,6 +791,18 @@ describe("Crafatar", function() {
}); });
}); });
it("should return 304 on server error", function(done) {
var original_timeout = config.server.http_timeout;
config.server.http_timeout = 1;
request.get({url: "http://localhost:3000/avatars/whatever", headers: {"If-None-Match": '"some-etag"'}}, function(error, res, body) {
assert.ifError(error);
assert.ifError(body);
assert.strictEqual(res.statusCode, 304);
config.server.http_timeout = original_timeout;
done();
});
});
it("should return a 422 (invalid size)", function(done) { it("should return a 422 (invalid size)", function(done) {
var size = config.avatars.max_size + 1; var size = config.avatars.max_size + 1;
request.get("http://localhost:3000/avatars/Jake_0?size=" + size, function(error, res, body) { request.get("http://localhost:3000/avatars/Jake_0?size=" + size, function(error, res, body) {