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
|
num = 0
|
||||||
ok = False
|
ok = False
|
||||||
binary = False
|
binary = False
|
||||||
|
found = False
|
||||||
while True:
|
while True:
|
||||||
gemresponse = gemsocket.recv(2048)
|
gemresponse = gemsocket.recv(1)
|
||||||
|
gemraw.append(gemresponse[0])
|
||||||
try:
|
try:
|
||||||
if num == 0:
|
if num == 0:
|
||||||
print(gemresponse)
|
print(gemresponse)
|
||||||
try:
|
try:
|
||||||
mimetype = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[1].split(";")[0]
|
if "\r" in bytes(gemraw).decode() and not found:
|
||||||
ok = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[0][0] == "2"
|
found = True
|
||||||
print("Non-ordinary type! " + mimetype)
|
mimetype = bytes(gemraw).decode()[:-1].split(" ")[1]
|
||||||
|
ok = bytes(gemraw).decode()[:-1].split(" ")[0][0] == 2
|
||||||
|
print(mimetype)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
elif num >= 1 and ok and not mimetype in ["text/gemini", ""]:
|
|
||||||
for i in gemresponse:
|
|
||||||
gemraw.append(i)
|
|
||||||
try:
|
try:
|
||||||
if gemresponse.decode() != "":
|
if gemresponse.decode() != "":
|
||||||
received += gemresponse.decode()
|
received += gemresponse.decode()
|
||||||
|
@ -59,7 +60,6 @@ def relay():
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
binary = True
|
binary = True
|
||||||
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(num)
|
print(num)
|
||||||
|
|
Loading…
Add table
Reference in a new issue