Browse Source

log response ID first for access log

also made sure 'headers' is defined before it's used
jomo 9 năm trước cách đây
mục cha
commit
d49f7279b3
1 tập tin đã thay đổi với 10 bổ sung10 xóa
  1. 10 10
      lib/response.js

+ 10 - 10
lib/response.js

@@ -26,27 +26,27 @@ var silent_errors = ["ETIMEDOUT", "ESOCKETTIMEDOUT", "ECONNRESET", "EHOSTUNREACH
 //  * hash:     image hash, required when body is an image
 //  * err:      a possible Error
 module.exports = function(request, response, result) {
+  // These headers are the same for every response
+  var headers = {
+    "Content-Type": result.body && result.type || "text/plain",
+    "Cache-Control": "max-age=" + config.caching.browser + ", public",
+    "Response-Time": Date.now() - request.start,
+    "X-Request-ID": request.id,
+    "Access-Control-Allow-Origin": "*"
+  };
+
   response.on("close", function() {
     logging.warn(request.id, "Connection closed");
   });
 
   response.on("finish", function() {
-    logging.log(request.method, request.url.href, request.id, response.statusCode, headers["Response-Time"] + "ms", "(" + (human_status[result.status] || "-") + ")");
+    logging.log(request.id, request.method, request.url.href, response.statusCode, headers["Response-Time"] + "ms", "(" + (human_status[result.status] || "-") + ")");
   });
 
   response.on("error", function(err) {
     logging.error(request.id, err);
   });
 
-  // These headers are the same for every response
-  var headers = {
-    "Content-Type": result.body && result.type || "text/plain",
-    "Cache-Control": "max-age=" + config.caching.browser + ", public",
-    "Response-Time": Date.now() - request.start,
-    "X-Request-ID": request.id,
-    "Access-Control-Allow-Origin": "*"
-  };
-
   if (result.err) {
     var silent = silent_errors.indexOf(result.err.code) !== -1;
     if (result.err.stack && !silent) {