瀏覽代碼

Merge pull request #559 from Unrud/remotehostlogging

Cleanup remote host logging
Guillaume Ayoub 9 年之前
父節點
當前提交
33b27a2e71
共有 1 個文件被更改,包括 12 次插入13 次删除
  1. 12 13
      radicale/__init__.py

+ 12 - 13
radicale/__init__.py

@@ -310,20 +310,19 @@ class Application:
             return [answer] if answer else []
 
         remote_host = "UNKNOWN"
-        if "REMOTE_HOST" in environ:
-            if environ["REMOTE_HOST"]:
-                remote_host = environ["REMOTE_HOST"]
-        if "HTTP_X_FORWARDED_FOR" in environ:
-            if environ["HTTP_X_FORWARDED_FOR"]:
-                remote_host = environ["HTTP_X_FORWARDED_FOR"]
-        remote_useragent = "[-no-user-agent-provided-]"
-        if "HTTP_USER_AGENT" in environ:
-            if environ["HTTP_USER_AGENT"]:
-                remote_useragent = environ["HTTP_USER_AGENT"]
+        if environ.get("REMOTE_HOST"):
+            remote_host = environ["REMOTE_HOST"]
+        elif environ.get("REMOTE_ADDR"):
+            remote_host = environ["REMOTE_ADDR"]
+        if environ.get("HTTP_X_FORWARDED_FOR"):
+            remote_host = "%s (forwarded by %s)" % (
+                environ["HTTP_X_FORWARDED_FOR"], remote_host)
+        remote_useragent = "UNKNOWN"
+        if environ.get("HTTP_USER_AGENT"):
+            remote_useragent = environ["HTTP_USER_AGENT"]
         depthinfo = ""
-        if "HTTP_DEPTH" in environ:
-            if environ["HTTP_DEPTH"]:
-                depthinfo = " with depth " + environ["HTTP_DEPTH"]
+        if environ.get("HTTP_DEPTH"):
+            depthinfo = " with depth " + environ["HTTP_DEPTH"]
         time_begin = datetime.datetime.now()
         self.logger.info(
             "%s request for %s received from %s using \"%s\"",