Update server.py

This commit is contained in:
Nova Cat 2025-01-13 21:52:44 -08:00
parent 7491d85bc7
commit e0970523ad

View file

@ -32,15 +32,33 @@ def relay():
gemsocket.connect((urlparse(fulladdr).hostname, 1965))
gemsocket.send(bytes(fulladdr + "\r\n", "UTF-8"))
received = ""
mimetype = ""
gemraw = bytearray()
num = 0
while True:
gemresponse = gemsocket.recv(2048)
try:
if num = 0:
try:
mimetype = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[1].split(";")[0]
if mimetype != "text/gemini".lower() and gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[0][0] != "2":
print("Non-ordinary type! " + mimetype)
except:
pass
elif num = 1 and not mimetype in ["text/gemini", ""]:
pass
elif num >= 2 and not mimetype in ["text/gemini", ""]:
for i in gemresponse:
gemraw.append(i)
if gemresponse.decode() != "":
received += gemresponse.decode()
else:
break
num+=1
except:
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="/style.css"><title>Something went wrong...</title></head><body><h1>Something went wrong...</h1><p>The file that the Gemini server sent couldn\'t be decoded by Gem2Browser.</p></body></html>'
if not mimetype.lower() in ["text/gemini", ""]:
return bytes(gemraw)
received = received.replace("\r", "")
firstline = True
redirected = False