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
This commit is contained in:
hanishkvc 2025-12-09 21:25:53 +05:30
parent e04afaa6ff
commit e67734fa22
2 changed files with 13 additions and 0 deletions

View File

@ -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

View File

@ -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