don't respond with 304 on error when debugging is enabled

This commit is contained in:
jomo 2016-11-07 04:08:19 +01:00
parent f1f3ba6709
commit c02d3d33e9
2 changed files with 5 additions and 1 deletions

View File

@ -70,7 +70,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"];
// also respond with 304 on server error (use client's version) // also respond with 304 on server error (use client's version)
if (incoming_etag && (incoming_etag === etag || result.status === -1)) { // don't respond with 304 when debugging is enabled
if (incoming_etag && (incoming_etag === etag || result.status === -1 && !config.server.debug_enabled)) {
response.writeHead(304, headers); response.writeHead(304, headers);
response.end(); response.end();
return; return;

View File

@ -801,12 +801,15 @@ describe("Crafatar", function() {
}); });
it("should return 304 on server error", function(done) { it("should return 304 on server error", function(done) {
var original_debug = config.server.debug_enabled;
var original_timeout = config.server.http_timeout; var original_timeout = config.server.http_timeout;
config.server.debug_enabled = false;
config.server.http_timeout = 1; config.server.http_timeout = 1;
request.get({url: "http://localhost:3000/avatars/whatever", headers: {"If-None-Match": '"some-etag"'}}, function(error, res, body) { request.get({url: "http://localhost:3000/avatars/whatever", headers: {"If-None-Match": '"some-etag"'}}, function(error, res, body) {
assert.ifError(error); assert.ifError(error);
assert.ifError(body); assert.ifError(body);
assert.strictEqual(res.statusCode, 304); assert.strictEqual(res.statusCode, 304);
config.server.debug_enabled = original_debug;
config.server.http_timeout = original_timeout; config.server.http_timeout = original_timeout;
done(); done();
}); });