feat(web): visit 204 response, up page header/sort, trim system page
This commit is contained in:
1 parent
e3bd2e601b
commit
84ce1e41e8
7 files changed
+41
-54
No files matched your search
+16
-16
@@ -194,37 +194,37 @@ def test_visit_endpoint_and_stats():
|
||||
running = RunningServer(tmp)
|
||||
try:
|
||||
ua = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/155.0"}
|
||||
# 上报:可信对端 127.0.0.1 + X-Real-IP → 记录真实 IP 与归一化路由
|
||||
status, _, payload = running.json(
|
||||
collector = running.server.context.visits
|
||||
|
||||
# 上报:返回 204(无响应体),可信对端 + X-Real-IP → 记录真实 IP 与归一化路由
|
||||
status, _, body = running.request(
|
||||
"/api/visit", method="POST",
|
||||
headers={**ua, "Content-Type": "application/json", "X-Real-IP": "203.0.113.7"},
|
||||
body=json.dumps({"path": "/video/123"}),
|
||||
)
|
||||
assert status == 200 and payload["data"]["recorded"] is True
|
||||
assert payload["data"]["route"] == "/video/:aid"
|
||||
|
||||
status, _, payload = running.json(
|
||||
assert status == 204 and body == b""
|
||||
status, _, body = running.request(
|
||||
"/api/visit", method="POST",
|
||||
headers={**ua, "Content-Type": "application/json", "X-Real-IP": "203.0.113.7"},
|
||||
body=json.dumps({"path": "/videos"}),
|
||||
)
|
||||
assert status == 200 and payload["data"]["recorded"] is True
|
||||
assert status == 204 and body == b""
|
||||
|
||||
collector = running.server.context.visits
|
||||
assert collector.pending_keys == 2
|
||||
routes = {(row["ip"], row["path"]) for row in collector.pending_rows()}
|
||||
assert routes == {("203.0.113.7", "/video/:aid"), ("203.0.113.7", "/videos")}
|
||||
|
||||
# 机器人 UA 被过滤,不计数
|
||||
status, _, payload = running.json(
|
||||
status, _, body = running.request(
|
||||
"/api/visit", method="POST",
|
||||
headers={"User-Agent": "Googlebot/2.1", "Content-Type": "application/json"},
|
||||
body=json.dumps({"path": "/home"}),
|
||||
)
|
||||
assert status == 200 and payload["data"]["recorded"] is False
|
||||
assert payload["data"]["reason"] == "bot"
|
||||
assert status == 204
|
||||
assert collector.pending_keys == 2
|
||||
|
||||
# 超大请求体被拒绝
|
||||
status, _, _ = running.json(
|
||||
# 超大请求体被拒绝(JSON 错误仍返回)
|
||||
status, _, _ = running.request(
|
||||
"/api/visit", method="POST",
|
||||
headers={**ua, "Content-Type": "application/json"},
|
||||
body=json.dumps({"path": "/" + "x" * 4000}),
|
||||
@@ -283,9 +283,9 @@ def test_visit_query_path_drains_body():
|
||||
headers={**ua, "Content-Type": "application/json"},
|
||||
)
|
||||
first = conn.getresponse()
|
||||
first_payload = json.loads(first.read())
|
||||
assert first.status == 200
|
||||
assert first_payload["data"]["route"] == "/about"
|
||||
assert first.status == 204 and first.read() == b""
|
||||
# 路径来自查询串而非请求体
|
||||
assert running.server.context.visits.pending_rows()[0]["path"] == "/about"
|
||||
|
||||
# 同一连接继续发请求:若上一次请求体未被读走,这里会解析错位
|
||||
conn.request("GET", "/api/health")
|
||||
|
||||
Reference in new issue
Block a user