fixing bugs
All checks were successful
Build Docker Image / build (push) Successful in 5m5s

This commit is contained in:
Tudor Sitaru
2025-10-14 20:46:52 +01:00
parent e17d69c308
commit e062b51b4b
2 changed files with 28 additions and 2 deletions

View File

@@ -249,6 +249,12 @@ python webserver.py --port 8080
- Check that asset files are properly referenced in HTML
- Verify file permissions on asset files
#### AttributeError: 'Application' object has no attribute 'remote'
This error occurs with older versions of aiohttp. The web server has been updated to use the correct request attributes:
- Uses `request.transport.get_extra_info("peername")` for client IP
- Handles cases where transport is not available
- Falls back to "unknown" for client identification
### Debug Mode
For more verbose logging, modify the logging level:

View File

@@ -387,13 +387,32 @@ class SnapshotsWebServer:
async def logging_middleware(request, handler):
start_time = datetime.now()
# Get client IP address
def get_client_ip():
# Check for forwarded header first
forwarded = request.headers.get("X-Forwarded-For")
if forwarded:
return forwarded.split(",")[0].strip()
# Try to get from transport
try:
if request.transport:
peername = request.transport.get_extra_info("peername")
if peername:
return peername[0]
except:
pass
return "unknown"
try:
response = await handler(request)
# Log the request
duration = (datetime.now() - start_time).total_seconds()
remote_addr = get_client_ip()
self.logger.info(
f"{request.remote} - {request.method} {request.path} - "
f"{remote_addr} - {request.method} {request.path} - "
f"{response.status} - {duration:.3f}s"
)
@@ -401,8 +420,9 @@ class SnapshotsWebServer:
except Exception as e:
duration = (datetime.now() - start_time).total_seconds()
remote_addr = get_client_ip()
self.logger.error(
f"{request.remote} - {request.method} {request.path} - "
f"{remote_addr} - {request.method} {request.path} - "
f"ERROR: {e} - {duration:.3f}s"
)
raise