feat: web dynamic payload factory - #26
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
make_dashboard_server() 允许 payload 与 payload_factory 同时缺省会导致运行时崩溃,需要加入明确校验并修正已指出的问题。
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
该 PR 为 web serve 增加 payload_factory 支持,使本地只读 Web 工作台在每次请求时可重新生成 HTML,从而实现“真正的自动刷新”(而非仅刷新同一份静态 HTML)。
Changes:
- 扩展
make_dashboard_server()/serve_dashboard():新增payload_factory,按请求动态渲染页面 - 新增单测覆盖
payload_factory每次请求会被调用并反映在 HTML 中 - 更新 Changelog 与 Roadmap 记录该能力与测试数量变化
File summaries
| File | Description |
|---|---|
tests/test_web.py |
新增测试验证 payload_factory 在多次请求中动态更新页面内容 |
src/goratio/web.py |
web serve 增加 payload_factory 入口并在请求处理时动态渲染 HTML |
CHANGELOG.md |
记录 web serve 新增 payload_factory 支持 |
.planning/ROADMAP.md |
Roadmap 勾选完成项并更新当前测试数量 |
Review details
Suppressed comments (1)
src/goratio/web.py:152
- The handler encodes the HTML twice (once to compute Content-Length and again to write), which becomes more noticeable now that HTML may be regenerated per request. Encode once and reuse the bytes for both the length and write.
html = current_html()
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(html.encode("utf-8"))))
self.end_headers()
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
138
to
+143
| from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer | ||
|
|
||
| html = render_dashboard_html(payload, refresh_seconds=60) | ||
| def current_html(): | ||
| if payload_factory is not None: | ||
| return render_dashboard_html(payload_factory(), refresh_seconds=60) | ||
| return render_dashboard_html(payload, refresh_seconds=60) |
Comment on lines
+78
to
+81
| def test_readonly_server_supports_payload_factory(self) -> None: | ||
| from goratio.web import make_dashboard_server | ||
|
|
||
| calls = {"n": 0} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
web serve 支持 payload_factory,每次请求重新生成 HTML。