Update server.py

This commit is contained in:
Nova Cat 2025-01-13 21:57:21 -08:00
parent 31294aafb2
commit 72cfcfbdd1

View file

@ -35,6 +35,7 @@ def relay():
mimetype = ""
gemraw = bytearray()
num = 0
ok = False
while True:
gemresponse = gemsocket.recv(2048)
try:
@ -42,13 +43,12 @@ def relay():
try:
mimetype = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[1].split(";")[0]
ok = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[0][0] == "2"
if mimetype != "text/gemini".lower() and ok:
print("Non-ordinary type! " + mimetype)
print("Non-ordinary type! " + mimetype)
except:
pass
elif num == 1 and not mimetype in ["text/gemini", ""]:
elif num == 1 and ok and not mimetype in ["text/gemini", ""]:
pass
elif num >= 2 and not mimetype in ["text/gemini", ""]:
elif num >= 2 and ok and not mimetype in ["text/gemini", ""]:
for i in gemresponse:
gemraw.append(i)
if mimetype in ["text/gemini", ""] and gemresponse.decode() != "":
@ -59,7 +59,7 @@ def relay():
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>'
print(mimetype)
if not mimetype.lower() in ["text/gemini", ""]:
if ok and not mimetype.lower() in ["text/gemini", ""]:
return bytes(gemraw)
received = received.replace("\r", "")
firstline = True