Better logging (for the 3rd time), fix devices list over federation

This commit is contained in:
2025-10-13 17:55:48 -04:00
parent c8d6f57e5b
commit 9aa2e062e5
2 changed files with 28 additions and 5 deletions

View File

@@ -49,7 +49,6 @@ async def handle_logging(response):
response.headers["Access-Control-Allow-Methods"] = "GET, HEAD, POST, PUT, DELETE, OPTIONS"
if request.method == "OPTIONS":
# Discard logs for OPTIONS
return response
origin = "unknown"
@@ -57,13 +56,31 @@ async def handle_logging(response):
try:
if "Authorization" in request.headers:
if request.headers["Authorization"].split()[0] == "X-Matrix":
origin = request.headers["Authorization"].split('origin="')[1].split('"')[0]
origin = (
request.headers["Authorization"]
.split("origin=")[1]
.split(",")[0]
)
while '"' in origin:
origin = origin.replace('"', "")
if origin == config.server_name:
return response
else:
origin = "client"
except:
pass
print(f'[{origin}] [{request.remote_addr}] [{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] {request.method} {request.full_path} {response.status_code}')
print(
f"[{origin}] " +
f'[{datetime.now().strftime("%d/%b/%Y:%H:%M:%S")}] ' +
request.method + " " +
request.full_path.rstrip("?") + " " +
str(response.status_code)
)
return response
@@ -115,7 +132,13 @@ async def client():
def federation_self_test():
try:
resp = globals.http_client.get(f"https://{config.server_name}/.well-known/matrix/server")
auth = globals.make_auth_header(config.server_name, "GET", "/.well-known/matrix/server")
resp = globals.http_client.get(
f"https://{config.server_name}/.well-known/matrix/server",
headers={"Authorization": auth}
)
resp.raise_for_status()
print("[INFO] Federation self-test OK")
except Exception as e:

View File

@@ -404,7 +404,7 @@ async def user_profile():
async def user_devices(user):
return jsonify({
"devices": [],
"stream_id": the_funny_number,
"stream_id": config.the_funny_number,
"user_id": f"@vona:{config.server_name}"
})