Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def log_request(self, code: str='-', size: str='-') -> None:
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,
})
Expand Down
18 changes: 18 additions & 0 deletions tests/test_issue2775_log_request.py
Original file line number Diff line number Diff line change
@@ -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
Loading