Update server.py
This commit is contained in:
parent
f7ef958cf4
commit
e5dd00ae73
1 changed files with 9 additions and 5 deletions
14
server.py
14
server.py
|
@ -36,6 +36,7 @@ def relay():
|
||||||
gemraw = bytearray()
|
gemraw = bytearray()
|
||||||
num = 0
|
num = 0
|
||||||
ok = False
|
ok = False
|
||||||
|
binary = False
|
||||||
while True:
|
while True:
|
||||||
gemresponse = gemsocket.recv(2048)
|
gemresponse = gemsocket.recv(2048)
|
||||||
try:
|
try:
|
||||||
|
@ -51,15 +52,18 @@ def relay():
|
||||||
elif num >= 2 and ok and not mimetype in ["text/gemini", ""]:
|
elif num >= 2 and ok and not mimetype in ["text/gemini", ""]:
|
||||||
for i in gemresponse:
|
for i in gemresponse:
|
||||||
gemraw.append(i)
|
gemraw.append(i)
|
||||||
if ok and mimetype in ["text/gemini", ""] and gemresponse.decode() != "":
|
try:
|
||||||
received += gemresponse.decode()
|
if gemresponse.decode() != "":
|
||||||
else:
|
received += gemresponse.decode()
|
||||||
break
|
else:
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
binary = True
|
||||||
num+=1
|
num+=1
|
||||||
except:
|
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>'
|
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)
|
print(mimetype)
|
||||||
if ok and not mimetype.lower() in ["text/gemini", ""]:
|
if binary:
|
||||||
return bytes(gemraw)
|
return bytes(gemraw)
|
||||||
received = received.replace("\r", "")
|
received = received.replace("\r", "")
|
||||||
firstline = True
|
firstline = True
|
||||||
|
|
Loading…
Add table
Reference in a new issue