fix: selftest 所有 API 请求补 operationID 头(OpenIM 强制校验)
This commit is contained in:
+4
-2
@@ -30,11 +30,13 @@ fail() { echo " [失败] $1"; FAILED=1; }
|
||||
note() { echo " [提示] $1"; }
|
||||
|
||||
# 优先用宿主机 curl;没有则在容器里跑 curl
|
||||
# OpenIM 所有 API 都要求 operationID 请求头(链路追踪用,每次请求唯一即可)
|
||||
new_opid() { echo "selftest-$(date +%s%N 2>/dev/null || date +%s)-$RANDOM"; }
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
http_post() { curl -s -m 15 -X POST "$1" -H 'Content-Type: application/json' ${TOKEN:+-H "token: $TOKEN"} -d "$2"; }
|
||||
http_post() { curl -s -m 15 -X POST "$1" -H 'Content-Type: application/json' -H "operationID: $(new_opid)" ${TOKEN:+-H "token: $TOKEN"} -d "$2"; }
|
||||
else
|
||||
note "宿主机无 curl,使用容器化 curl"
|
||||
http_post() { docker run --rm --network host curlimages/curl:8.10.1 -s -m 15 -X POST "$1" -H 'Content-Type: application/json' ${TOKEN:+-H "token: $TOKEN"} -d "$2"; }
|
||||
http_post() { docker run --rm --network host curlimages/curl:8.10.1 -s -m 15 -X POST "$1" -H 'Content-Type: application/json' -H "operationID: $(new_opid)" ${TOKEN:+-H "token: $TOKEN"} -d "$2"; }
|
||||
fi
|
||||
|
||||
json_ok() { echo "$1" | tr -d ' \n' | grep -q '"errCode":0'; }
|
||||
|
||||
Reference in New Issue
Block a user