Fix heartbeat POST handling
This commit is contained in:
1 parent
776400a107
commit
151f5353bb
2 files changed
+22
-7
No files matched your search
@@ -294,13 +294,6 @@ post_json() {
|
||||
token="$2"
|
||||
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
|
||||
wget -q -O - \
|
||||
--header="Authorization: Bearer $token" \
|
||||
@@ -315,6 +308,13 @@ post_json() {
|
||||
--data-binary "@$file" "$url"
|
||||
return
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
@@ -690,6 +690,20 @@ class Handler(BaseHTTPRequestHandler):
|
||||
return False
|
||||
|
||||
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")
|
||||
return self.rfile.read(length) if length else b""
|
||||
|
||||
@@ -743,6 +757,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
router = heartbeat(conn, payload)
|
||||
self.send_json(200, {"ok": True, "router": router})
|
||||
except Exception as exc:
|
||||
self.log_message("heartbeat error: %s", exc)
|
||||
self.send_json(400, {"ok": False, "error": str(exc)})
|
||||
return
|
||||
if path.startswith("/access/"):
|
||||
|
||||
Reference in new issue
Block a user