Update server.py
This commit is contained in:
parent
4b17fb4bbf
commit
1657508808
1 changed files with 8 additions and 8 deletions
16
server.py
16
server.py
|
@ -38,20 +38,21 @@ def relay():
|
|||
num = 0
|
||||
ok = False
|
||||
binary = False
|
||||
found = False
|
||||
while True:
|
||||
gemresponse = gemsocket.recv(2048)
|
||||
gemresponse = gemsocket.recv(1)
|
||||
gemraw.append(gemresponse[0])
|
||||
try:
|
||||
if num == 0:
|
||||
print(gemresponse)
|
||||
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"
|
||||
print("Non-ordinary type! " + mimetype)
|
||||
if "\r" in bytes(gemraw).decode() and not found:
|
||||
found = True
|
||||
mimetype = bytes(gemraw).decode()[:-1].split(" ")[1]
|
||||
ok = bytes(gemraw).decode()[:-1].split(" ")[0][0] == 2
|
||||
print(mimetype)
|
||||
except:
|
||||
pass
|
||||
elif num >= 1 and ok and not mimetype in ["text/gemini", ""]:
|
||||
for i in gemresponse:
|
||||
gemraw.append(i)
|
||||
try:
|
||||
if gemresponse.decode() != "":
|
||||
received += gemresponse.decode()
|
||||
|
@ -59,7 +60,6 @@ def relay():
|
|||
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(num)
|
||||
|
|
Loading…
Add table
Reference in a new issue