diff --git a/server.py b/server.py index 8df8613..7ab9d1a 100644 --- a/server.py +++ b/server.py @@ -32,15 +32,33 @@ def relay(): gemsocket.connect((urlparse(fulladdr).hostname, 1965)) gemsocket.send(bytes(fulladdr + "\r\n", "UTF-8")) received = "" + mimetype = "" + gemraw = bytearray() + num = 0 while True: gemresponse = gemsocket.recv(2048) try: + if num = 0: + try: + mimetype = gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[1].split(";")[0] + if mimetype != "text/gemini".lower() and gemresponse.decode().replace("\r","").split("\n")[0].split(" ")[0][0] != "2": + print("Non-ordinary type! " + mimetype) + except: + pass + elif num = 1 and not mimetype in ["text/gemini", ""]: + pass + elif num >= 2 and not mimetype in ["text/gemini", ""]: + for i in gemresponse: + gemraw.append(i) if gemresponse.decode() != "": received += gemresponse.decode() else: break + num+=1 except: return f'\n
The file that the Gemini server sent couldn\'t be decoded by Gem2Browser.
' + if not mimetype.lower() in ["text/gemini", ""]: + return bytes(gemraw) received = received.replace("\r", "") firstline = True redirected = False