diff --git a/server.py b/server.py index 504da03..9721a58 100644 --- a/server.py +++ b/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'\nSomething went wrong...

Something went wrong...

The file that the Gemini server sent couldn\'t be decoded by Gem2Browser.

' print(num)