Fix heartbeat POST handling

This commit is contained in:
kzolotarev95 committed 2026-06-29 04:13:37 +04:00
1 parent 776400a107
commit 151f5353bb
2 files changed
+22 -7

No files matched your search

+7 -7
View File
@@ -294,13 +294,6 @@ post_json() {
token="$2" token="$2"
file="$3" file="$3"
if command -v uclient-fetch >/dev/null 2>&1; then
uclient-fetch -q -O - \
--header="Authorization: Bearer $token" \
--header="Content-Type: application/json" \
--post-file="$file" "$url"
return
fi
if command -v wget >/dev/null 2>&1; then if command -v wget >/dev/null 2>&1; then
wget -q -O - \ wget -q -O - \
--header="Authorization: Bearer $token" \ --header="Authorization: Bearer $token" \
@@ -315,6 +308,13 @@ post_json() {
--data-binary "@$file" "$url" --data-binary "@$file" "$url"
return return
fi fi
if command -v uclient-fetch >/dev/null 2>&1; then
uclient-fetch -q -O - \
--header="Authorization: Bearer $token" \
--header="Content-Type: application/json" \
--post-file="$file" "$url"
return
fi
die "для heartbeat нужен uclient-fetch, wget или curl" die "для heartbeat нужен uclient-fetch, wget или curl"
} }
+15
View File
@@ -690,6 +690,20 @@ class Handler(BaseHTTPRequestHandler):
return False return False
def read_body(self): def read_body(self):
if self.headers.get("Transfer-Encoding", "").lower() == "chunked":
chunks = []
while True:
line = self.rfile.readline().strip()
if not line:
continue
size = int(line.split(b";", 1)[0], 16)
if size == 0:
while self.rfile.readline().strip():
pass
break
chunks.append(self.rfile.read(size))
self.rfile.read(2)
return b"".join(chunks)
length = int(self.headers.get("Content-Length", "0") or "0") length = int(self.headers.get("Content-Length", "0") or "0")
return self.rfile.read(length) if length else b"" return self.rfile.read(length) if length else b""
@@ -743,6 +757,7 @@ class Handler(BaseHTTPRequestHandler):
router = heartbeat(conn, payload) router = heartbeat(conn, payload)
self.send_json(200, {"ok": True, "router": router}) self.send_json(200, {"ok": True, "router": router})
except Exception as exc: except Exception as exc:
self.log_message("heartbeat error: %s", exc)
self.send_json(400, {"ok": False, "error": str(exc)}) self.send_json(400, {"ok": False, "error": str(exc)})
return return
if path.startswith("/access/"): if path.startswith("/access/"):