From 6f692a6d4483335b916a613f2e226a27e5652d9f Mon Sep 17 00:00:00 2001 From: 9qeklajc <9qeklajc> Date: Sat, 26 Jul 2025 12:15:46 +0200 Subject: [PATCH] fmt --- router/cashu.py | 1 + router/logging_config.py | 5 +++-- router/payment/x_cashu.py | 13 +++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/router/cashu.py b/router/cashu.py index 5a66fd9a..eb546198 100644 --- a/router/cashu.py +++ b/router/cashu.py @@ -516,6 +516,7 @@ async def redeem(cashu_token: str, lnurl: str) -> int: "amount": amount, "unit": unit, "lnurl_preview": lnurl[:20] + "..." if len(lnurl) > 20 else lnurl, + "transaction_result": str(result), }, ) diff --git a/router/logging_config.py b/router/logging_config.py index 18b1a0e5..d7b08a83 100644 --- a/router/logging_config.py +++ b/router/logging_config.py @@ -3,6 +3,7 @@ import os import re import tomllib from pathlib import Path + from pythonjsonlogger import jsonlogger @@ -68,8 +69,8 @@ class SecurityFilter(logging.Filter): patterns = [ rf"{key}[:\s=]+([a-zA-Z0-9_\-\.]+)", # key: value or key=value rf'{key}[:\s=]+["\']([^"\']+)["\']', # key: "value" or key='value' - rf"Bearer\s+([a-zA-Z0-9_\-\.]+)", # Bearer token - rf"cashu[A-Z]+([a-zA-Z0-9_\-\.=/+]+)", # Cashu tokens + r"Bearer\s+([a-zA-Z0-9_\-\.]+)", # Bearer token + r"cashu[A-Z]+([a-zA-Z0-9_\-\.=/+]+)", # Cashu tokens ] for pattern in patterns: diff --git a/router/payment/x_cashu.py b/router/payment/x_cashu.py index 9a5a9650..36f3e7d2 100644 --- a/router/payment/x_cashu.py +++ b/router/payment/x_cashu.py @@ -259,6 +259,13 @@ async def handle_streaming_response( }, ) + # Initialize response headers early so they can be modified during processing + response_headers = dict(response.headers) + if "transfer-encoding" in response_headers: + del response_headers["transfer-encoding"] + if "content-encoding" in response_headers: + del response_headers["content-encoding"] + # For streaming responses, we'll extract the final usage data # and calculate cost based on that usage_data = None @@ -342,12 +349,6 @@ async def handle_streaming_response( }, ) - response_headers = dict(response.headers) - if "transfer-encoding" in response_headers: - del response_headers["transfer-encoding"] - if "content-encoding" in response_headers: - del response_headers["content-encoding"] - async def generate() -> AsyncGenerator[bytes, None]: for line in lines: yield (line + "\n").encode("utf-8")