mirror of
https://github.com/masterking32/MasterHttpRelayVPN.git
synced 2026-05-18 07:34:35 +03:00
fix: improve error handling in proxy server and h2 transport classes
This commit is contained in:
@@ -1752,4 +1752,4 @@ class DomainFronter:
|
||||
f"Content-Length: {len(body)}\r\n"
|
||||
f"\r\n"
|
||||
f"{body}"
|
||||
).encode()
|
||||
).encode()
|
||||
|
||||
@@ -363,6 +363,15 @@ class H2Transport:
|
||||
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
except ssl.SSLError as e:
|
||||
# APPLICATION_DATA_AFTER_CLOSE_NOTIFY is raised when the server
|
||||
# sends data after its TLS close_notify — technically a protocol
|
||||
# violation but very common with CDNs. It just means the
|
||||
# connection is closed; reconnect on the next request.
|
||||
if "APPLICATION_DATA_AFTER_CLOSE_NOTIFY" in str(e):
|
||||
log.debug("H2 TLS session closed by remote (close_notify): %s", e)
|
||||
else:
|
||||
log.error("H2 reader error: %s", e)
|
||||
except Exception as e:
|
||||
log.error("H2 reader error: %s", e)
|
||||
finally:
|
||||
|
||||
+12
-3
@@ -1014,7 +1014,7 @@ class ProxyServer:
|
||||
headers[k.strip()] = v.strip()
|
||||
|
||||
# Shortening the length of X API URLs to prevent relay errors.
|
||||
if host == "x.com" and re.match(r"/i/api/graphql/[^/]+/[^?]+\?variables=", path):
|
||||
if host == "x.com" and re.match(r"/i/api/graphql/[^/]+/[^?]+\?variables=", path):
|
||||
path = path.split("&")[0]
|
||||
|
||||
# MITM traffic arrives as origin-form paths; SOCKS/plain HTTP can
|
||||
@@ -1062,9 +1062,18 @@ class ProxyServer:
|
||||
# Relay through Apps Script
|
||||
try:
|
||||
response = await self._relay_smart(method, url, headers, body, writer)
|
||||
except asyncio.TimeoutError:
|
||||
log.warning("Relay timeout (%s)", url[:60])
|
||||
response = (
|
||||
b"HTTP/1.1 504 Gateway Timeout\r\n"
|
||||
b"Content-Type: text/plain\r\n"
|
||||
b"Content-Length: 13\r\n"
|
||||
b"\r\nRelay timeout"
|
||||
)
|
||||
except Exception as e:
|
||||
log.error("Relay error (%s): %s", url[:60], e)
|
||||
err_body = f"Relay error: {e}".encode()
|
||||
err_label = str(e) or type(e).__name__
|
||||
log.error("Relay error (%s): %s", url[:60], err_label)
|
||||
err_body = f"Relay error: {err_label}".encode()
|
||||
response = (
|
||||
b"HTTP/1.1 502 Bad Gateway\r\n"
|
||||
b"Content-Type: text/plain\r\n"
|
||||
|
||||
Reference in New Issue
Block a user