Update server.py
This commit is contained in:
parent
31294aafb2
commit
72cfcfbdd1
1 changed files with 5 additions and 5 deletions
|
@ -35,6 +35,7 @@ def relay():
|
||||||
mimetype = ""
|
mimetype = ""
|
||||||
gemraw = bytearray()
|
gemraw = bytearray()
|
||||||
num = 0
|
num = 0
|
||||||
|
ok = False
|
||||||
while True:
|
while True:
|
||||||
gemresponse = gemsocket.recv(2048)
|
gemresponse = gemsocket.recv(2048)
|
||||||
try:
|
try:
|
||||||
|
@ -42,13 +43,12 @@ def relay():
|
||||||
try:
|
try:
|
||||||
mimetype = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[1].split(";")[0]
|
mimetype = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[1].split(";")[0]
|
||||||
ok = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[0][0] == "2"
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
elif num == 1 and not mimetype in ["text/gemini", ""]:
|
elif num == 1 and ok and not mimetype in ["text/gemini", ""]:
|
||||||
pass
|
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:
|
for i in gemresponse:
|
||||||
gemraw.append(i)
|
gemraw.append(i)
|
||||||
if mimetype in ["text/gemini", ""] and gemresponse.decode() != "":
|
if mimetype in ["text/gemini", ""] and gemresponse.decode() != "":
|
||||||
|
@ -59,7 +59,7 @@ def relay():
|
||||||
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 not mimetype.lower() in ["text/gemini", ""]:
|
if ok and not mimetype.lower() in ["text/gemini", ""]:
|
||||||
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