d
This commit is contained in:
62
API/HTTP.py
62
API/HTTP.py
@@ -453,6 +453,29 @@ class HTTPClient:
|
||||
|
||||
last_exception: Exception | None = None
|
||||
|
||||
def _raw_debug_enabled() -> bool:
|
||||
try:
|
||||
val = str(os.environ.get("MM_HTTP_RAW", "")).strip().lower()
|
||||
if val in {"0", "false", "no", "off"}:
|
||||
return False
|
||||
return is_debug_enabled()
|
||||
except Exception:
|
||||
return is_debug_enabled()
|
||||
|
||||
def _preview(value: Any, *, limit: int = 2000) -> str:
|
||||
if value is None:
|
||||
return "<null>"
|
||||
try:
|
||||
if isinstance(value, (dict, list, tuple)):
|
||||
text = json.dumps(value, ensure_ascii=False)
|
||||
else:
|
||||
text = str(value)
|
||||
except Exception:
|
||||
text = repr(value)
|
||||
if len(text) > limit:
|
||||
return text[:limit] + "..."
|
||||
return text
|
||||
|
||||
for attempt in range(self.retries):
|
||||
self._debug_panel(
|
||||
"HTTP request",
|
||||
@@ -466,6 +489,16 @@ class HTTPClient:
|
||||
("follow_redirects", kwargs.get("follow_redirects", False)),
|
||||
],
|
||||
)
|
||||
if _raw_debug_enabled():
|
||||
self._debug_panel(
|
||||
"HTTP request raw",
|
||||
[
|
||||
("params", _preview(kwargs.get("params"))),
|
||||
("data", _preview(kwargs.get("data"))),
|
||||
("json", _preview(kwargs.get("json"))),
|
||||
("content", _preview(kwargs.get("content"))),
|
||||
],
|
||||
)
|
||||
try:
|
||||
response = self._client.request(method, url, **kwargs)
|
||||
self._debug_panel(
|
||||
@@ -481,6 +514,35 @@ class HTTPClient:
|
||||
),
|
||||
],
|
||||
)
|
||||
if _raw_debug_enabled():
|
||||
content_type = ""
|
||||
try:
|
||||
content_type = response.headers.get("content-type", "")
|
||||
except Exception:
|
||||
content_type = ""
|
||||
body_preview = ""
|
||||
try:
|
||||
if isinstance(content_type, str) and (
|
||||
content_type.startswith("application/json")
|
||||
or content_type.startswith("text/")
|
||||
):
|
||||
body_preview = _preview(response.text, limit=4000)
|
||||
else:
|
||||
raw = response.content
|
||||
if raw is None:
|
||||
body_preview = "<no content>"
|
||||
else:
|
||||
body_preview = raw[:400].hex()
|
||||
except Exception:
|
||||
body_preview = "<unavailable>"
|
||||
self._debug_panel(
|
||||
"HTTP response raw",
|
||||
[
|
||||
("content_type", content_type),
|
||||
("body_preview", body_preview),
|
||||
("body_length", len(response.content) if response is not None else ""),
|
||||
],
|
||||
)
|
||||
if raise_for_status:
|
||||
response.raise_for_status()
|
||||
return response
|
||||
|
||||
@@ -622,7 +622,7 @@
|
||||
"(simfileshare\\.net/download/[0-9]+/)"
|
||||
],
|
||||
"regexp": "(simfileshare\\.net/download/[0-9]+/)",
|
||||
"status": true
|
||||
"status": false
|
||||
},
|
||||
"streamtape": {
|
||||
"name": "streamtape",
|
||||
|
||||
Reference in New Issue
Block a user