Skip to content

Commit 9afdaa5

Browse files
committed
protect against a bad request
1 parent cbb869b commit 9afdaa5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

http/web.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ async def send_file(writer, file):
6363
async def server(reader, writer):
6464
req = await reader.readline()
6565
print(req)
66-
method, uri, proto = req.split(b" ")
67-
m = re.match(url_pat, uri)
68-
route_req = m.group(5)
66+
try:
67+
method, uri, proto = req.split(b" ")
68+
m = re.match(url_pat, uri)
69+
route_req = m.group(5)
70+
except Exception as e:
71+
print("Malformed request: {}".format(req))
72+
writer.close
73+
await writer.close()
74+
return
6975

7076
while True:
7177
h = await reader.readline()

0 commit comments

Comments
 (0)