Spaces:
Sleeping
Sleeping
background request processing, no sleep loop, instant re-poll
Browse files1 unmodified line234567819 unmodified lines282930313233342 unmodified lines373839404142434445464748495051525354551 unmodified lineSERVER="https://mtsky-free-server-docker.hf.space"LOCAL_CGI="${LOCAL_CGI:-http://192.168.1.1/cgi-bin/api}"TMPDIR="/tmp/wstunnel"POLL_INTERVAL="${POLL_INTERVAL:-1}"UCLIENT="uclient-fetch -q -O - -T 10"mkdir -p "$TMPDIR"19 unmodified linesrc=$?if [ "$rc" != "0" ] || [ -z "$resp" ] || [ "$resp" = "{}" ]; then[ "$rc" != "0" ] && log "poll rc=$rc"sleep "$POLL_INTERVAL"continuefi2 unmodified linesif [ -n "$rid" ] && [ -n "$url_enc" ]; thenlocal_url="${LOCAL_CGI}?url=${url_enc}"log "request $rid"body_file="$TMPDIR/body-$rid"$UCLIENT "$local_url" > "$body_file" 2>&1u_rc=$?if [ "$u_rc" = "0" ] && [ -s "$body_file" ]; thenlog "success"respond "$rid" "200" "text/html" "$body_file" &elselog "local failed (rc=$u_rc)"echo "fetch failed rc=$u_rc" > "$body_file"respond "$rid" "502" "text/plain" "$body_file" &fifisleep "$POLL_INTERVAL"done1 unmodified line23456719 unmodified lines2728293031322 unmodified lines35363738394041424344454647484950511 unmodified lineSERVER="https://mtsky-free-server-docker.hf.space"LOCAL_CGI="${LOCAL_CGI:-http://192.168.1.1/cgi-bin/api}"TMPDIR="/tmp/wstunnel"UCLIENT="uclient-fetch -q -O - -T 10"mkdir -p "$TMPDIR"19 unmodified linesrc=$?if [ "$rc" != "0" ] || [ -z "$resp" ] || [ "$resp" = "{}" ]; then[ "$rc" != "0" ] && log "poll rc=$rc"continuefi2 unmodified linesif [ -n "$rid" ] && [ -n "$url_enc" ]; thenlocal_url="${LOCAL_CGI}?url=${url_enc}"body_file="$TMPDIR/body-$rid"($UCLIENT "$local_url" > "$body_file" 2>&1u_rc=$?if [ "$u_rc" = "0" ] && [ -s "$body_file" ]; thenrespond "$rid" "200" "text/html" "$body_file" >/dev/null 2>&1elseecho "fetch failed rc=$u_rc" > "$body_file"respond "$rid" "502" "text/plain" "$body_file" >/dev/null 2>&1firm -f "$body_file") &fidone
tunnel_client.sh+11-15