mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
respond 304 on server error, fixes #135
This commit is contained in:
parent
9ccb0151bc
commit
e7242ce773
@ -68,7 +68,8 @@ module.exports = function(request, response, result) {
|
||||
|
||||
// handle etag caching
|
||||
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.end();
|
||||
return;
|
||||
|
||||
12
test/test.js
12
test/test.js
@ -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) {
|
||||
var size = config.avatars.max_size + 1;
|
||||
request.get("http://localhost:3000/avatars/Jake_0?size=" + size, function(error, res, body) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user