[1mdiff --git a/README.md b/README.md[m
[1mindex a1af4b9..80b3f0a 100644[m
[1m--- a/README.md[m
[1m+++ b/README.md[m
[36m@@ -48,6 +48,7 @@[m [mThe log can be viewed via journalctl (or syslog):[m
[m
[32m+[m[32m* Respond with an error code to malformed UTF-8 in the request.[m
[m
[1mdiff --git a/gmcapsule/gemini.py b/gmcapsule/gemini.py[m
[1mindex b086ec6..34ac7f6 100644[m
[1m--- a/gmcapsule/gemini.py[m
[1m+++ b/gmcapsule/gemini.py[m
[36m@@ -376,22 +376,26 @@[m [mclass Worker(threading.Thread):[m
req_mime = None[m
incoming = safe_recv(stream, MAX_RECV)[m
[m
[31m- while len(data) < MAX_RECV:[m
[31m- data += incoming[m
[31m- crlf_pos = data.find(b'\r\n')[m
[31m- if crlf_pos >= 0:[m
[31m- request = data[:crlf_pos].decode('utf-8')[m
[31m- data = data[crlf_pos + 2:][m
[31m- break[m
[31m- elif len(data) > MAX_LEN:[m
[31m- # At this point we should have received the line terminator.[m
[31m- self.log(from_addr, 'sent a malformed request')[m
[31m- report_error(stream, 59, "Request exceeds maximum length")[m
[31m- return[m
[31m-[m
[31m- incoming = safe_recv(stream, MAX_RECV - len(data))[m
[31m- if len(incoming) <= 0:[m
[31m- break[m
[32m+[m[32m try:[m
[32m+[m[32m while len(data) < MAX_RECV:[m
[32m+[m[32m data += incoming[m
[32m+[m[32m crlf_pos = data.find(b'\r\n')[m
[32m+[m[32m if crlf_pos >= 0:[m
[32m+[m[32m request = data[:crlf_pos].decode('utf-8')[m
[32m+[m[32m data = data[crlf_pos + 2:][m
[32m+[m[32m break[m
[32m+[m[32m elif len(data) > MAX_LEN:[m
[32m+[m[32m # At this point we should have received the line terminator.[m
[32m+[m[32m self.log(from_addr, 'sent a malformed request')[m
[32m+[m[32m report_error(stream, 59, "Request exceeds maximum length")[m
[32m+[m[32m return[m
[32m+[m
[32m+[m[32m incoming = safe_recv(stream, MAX_RECV - len(data))[m
[32m+[m[32m if len(incoming) <= 0:[m
[32m+[m[32m break[m
[32m+[m[32m except UnicodeDecodeError:[m
[32m+[m[32m report_error(stream, 59, "Request contains malformed UTF-8")[m
[32m+[m[32m return[m
[m
if not request or len(data) > MAX_RECV:[m
report_error(stream, 59, "Invalid request")[m
text/plain
This content has been proxied by September (3851b).