Update server.py

This commit is contained in:
Nova Cat 2025-01-13 21:58:28 -08:00
parent f7ef958cf4
commit e5dd00ae73

View file

@ -36,6 +36,7 @@ def relay():
gemraw = bytearray()
num = 0
ok = False
binary = False
while True:
gemresponse = gemsocket.recv(2048)
try:
@ -51,15 +52,18 @@ def relay():
elif num >= 2 and ok and not mimetype in ["text/gemini", ""]:
for i in gemresponse:
gemraw.append(i)
if ok and mimetype in ["text/gemini", ""] and gemresponse.decode() != "":
received += gemresponse.decode()
else:
break
try:
if gemresponse.decode() != "":
received += gemresponse.decode()
else:
break
except:
binary = True
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>'
print(mimetype)
if ok and not mimetype.lower() in ["text/gemini", ""]:
if binary:
return bytes(gemraw)
received = received.replace("\r", "")
firstline = True