mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-05-26 19:50:15 +00:00
fix(server): tolerate malformed request logging
This commit is contained in:
committed by
nesquena-hermes
parent
2e876ea229
commit
618e1a5da8
@@ -3,6 +3,12 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Malformed HTTP request logging now falls back to `"-"` for missing method or
|
||||
path fields instead of raising an `AttributeError` traceback while handling
|
||||
the 400 response.
|
||||
|
||||
## [v0.51.124] — 2026-05-24 — Release CV (stage-batch6 — 3-PR Windows-only stack — agent paths / docs / port hardening)
|
||||
|
||||
### Added
|
||||
|
||||
@@ -232,8 +232,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
duration_ms = round((time.time() - getattr(self, '_req_t0', time.time())) * 1000, 1)
|
||||
record = _json.dumps({
|
||||
'ts': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
|
||||
'method': self.command or '-',
|
||||
'path': self.path or '-',
|
||||
'method': getattr(self, 'command', None) or '-',
|
||||
'path': getattr(self, 'path', None) or '-',
|
||||
'status': int(code) if str(code).isdigit() else code,
|
||||
'ms': duration_ms,
|
||||
})
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import json
|
||||
|
||||
from server import Handler
|
||||
|
||||
|
||||
def test_log_request_handles_malformed_request_without_path(capsys):
|
||||
"""Malformed request lines can call log_request before path is assigned."""
|
||||
handler = Handler.__new__(Handler)
|
||||
handler.command = None
|
||||
|
||||
Handler.log_request(handler, "400")
|
||||
|
||||
line = capsys.readouterr().out.strip()
|
||||
assert line.startswith("[webui] ")
|
||||
record = json.loads(line.removeprefix("[webui] "))
|
||||
assert record["method"] == "-"
|
||||
assert record["path"] == "-"
|
||||
assert record["status"] == 400
|
||||
Reference in New Issue
Block a user