From e67734fa229b72ff17701b7b9e5576fb4802e4ae Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Tue, 9 Dec 2025 21:25:53 +0530 Subject: [PATCH] SimpleSallap:SimpleMCP:Try identify https in http mode early Else python default http code will try interpret it has a malformed http request line and give failure lines like * bad version number * bad http/0.9 request etal along with a long bytes string following it --- tools/server/public_simplechat/local.tools/config.py | 4 ++++ tools/server/public_simplechat/local.tools/simplemcp.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/server/public_simplechat/local.tools/config.py b/tools/server/public_simplechat/local.tools/config.py index ae0f124afd..2a6c16b109 100644 --- a/tools/server/public_simplechat/local.tools/config.py +++ b/tools/server/public_simplechat/local.tools/config.py @@ -76,6 +76,10 @@ class Network(DictyDataclassMixin): class Op(DictyDataclassMixin): """ Used to store runtime operation related config entries and states + + Attributes: + sslContext: stores ssl context to use, + indirectly indicate if using https mode or not """ configFile: str = "/dev/null" debug: bool = False diff --git a/tools/server/public_simplechat/local.tools/simplemcp.py b/tools/server/public_simplechat/local.tools/simplemcp.py index 2e34f941b2..c916a1d621 100644 --- a/tools/server/public_simplechat/local.tools/simplemcp.py +++ b/tools/server/public_simplechat/local.tools/simplemcp.py @@ -18,6 +18,8 @@ import time import ssl import traceback import json +import select +import socket from typing import Any from dataclasses import asdict import tcpdf as mTCPdf @@ -197,6 +199,13 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler): if (gMe.op.sslContext): self.request = gMe.op.sslContext.wrap_socket(self.request, server_side=True) self.setup() + else: + conn: socket.socket = self.connection + readReady, _, _ = select.select([conn], [], [], 1.0) + if readReady: + peek = conn.recv(3, socket.MSG_PEEK) + if peek.startswith(b'\x16\x03'): + raise ConnectionError("Https in http mode???") except: print(f"ERRR:ProxyHandler:SSLHS:{traceback.format_exception_only(sys.exception())}") return