SimpleChatTC:SimpleProxy: Cleanup domain filtering and general

Had confused between js and python wrt accessing dictionary
contents and its consequence on non existent key. Fixed it.

Use different error ids to distinguish between failure in common
urlreq and the specific urltext and urlraw helpers.
This commit is contained in:
hanishkvc 2025-10-23 19:01:50 +05:30
parent 71ad609db6
commit 370326b1ec
1 changed files with 4 additions and 4 deletions

View File

@ -131,7 +131,7 @@ def handle_urlreq(pr: urllib.parse.ParseResult, tag: str):
url = url[0]
if (not url) or (len(url) == 0):
return UrlReqResp(False, 400, f"WARN:{tag}:MissingUrl")
if (not gMe['--allowed.domains']):
if (not gMe.get('--allowed.domains')):
return UrlReqResp(False, 400, f"DBUG:{tag}:MissingAllowedDomains")
gotVU = validate_url(url, tag)
if not gotVU.callOk:
@ -144,7 +144,7 @@ def handle_urlreq(pr: urllib.parse.ParseResult, tag: str):
contentType = response.getheader('Content-Type') or 'text/html'
return UrlReqResp(True, statusCode, "", contentType, contentData)
except Exception as exc:
return UrlReqResp(False, 502, f"WARN:UrlFetchFailed:{exc}")
return UrlReqResp(False, 502, f"WARN:UrlReqFailed:{exc}")
def handle_urlraw(ph: ProxyHandler, pr: urllib.parse.ParseResult):
@ -162,7 +162,7 @@ def handle_urlraw(ph: ProxyHandler, pr: urllib.parse.ParseResult):
ph.end_headers()
ph.wfile.write(got.contentData.encode('utf-8'))
except Exception as exc:
ph.send_error(502, f"WARN:UrlFetchFailed:{exc}")
ph.send_error(502, f"WARN:UrlRawFailed:{exc}")
class TextHtmlParser(html.parser.HTMLParser):
@ -260,7 +260,7 @@ def handle_urltext(ph: ProxyHandler, pr: urllib.parse.ParseResult):
ph.end_headers()
ph.wfile.write(textHtml.get_stripped_text().encode('utf-8'))
except Exception as exc:
ph.send_error(502, f"WARN:UrlFetchFailed:{exc}")
ph.send_error(502, f"WARN:UrlTextFailed:{exc}")
def load_config():