summary refs log tree commit diff
path: root/synapse/http/site.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2023-06-26 15:12:20 +0100
committerGitHub <noreply@github.com>2023-06-26 14:12:20 +0000
commit25c55a9d2267b09da3e18090ee538782d6771a27 (patch)
tree7d8aced4b661f7a2d260dba9a5f6f76693ee48fe /synapse/http/site.py
parentBump types-opentracing from 2.4.10.4 to 2.4.10.5 (#15830) (diff)
downloadsynapse-25c55a9d2267b09da3e18090ee538782d6771a27.tar.xz
Add login spam checker API (#15838)
Diffstat (limited to 'synapse/http/site.py')
-rw-r--r--synapse/http/site.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/synapse/http/site.py b/synapse/http/site.py
index c530966ef3..5b5a7c1e59 100644
--- a/synapse/http/site.py
+++ b/synapse/http/site.py
@@ -521,6 +521,11 @@ class SynapseRequest(Request):
         else:
             return self.getClientAddress().host
 
+    def request_info(self) -> "RequestInfo":
+        h = self.getHeader(b"User-Agent")
+        user_agent = h.decode("ascii", "replace") if h else None
+        return RequestInfo(user_agent=user_agent, ip=self.get_client_ip_if_available())
+
 
 class XForwardedForRequest(SynapseRequest):
     """Request object which honours proxy headers
@@ -661,3 +666,9 @@ class SynapseSite(Site):
 
     def log(self, request: SynapseRequest) -> None:
         pass
+
+
+@attr.s(auto_attribs=True, frozen=True, slots=True)
+class RequestInfo:
+    user_agent: Optional[str]
+    ip: str