Procházet zdrojové kódy

respond 304 on server error, fixes #135

jomo před 9 roky
rodič
revize
e7242ce773
2 změnil soubory, kde provedl 14 přidání a 1 odebrání
  1. 2 1
      lib/response.js
  2. 12 0
      test/test.js

+ 2 - 1
lib/response.js

@@ -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 - 0
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) {