diff --git a/echo.py b/echo.py index ffaad5a..98ee172 100755 --- a/echo.py +++ b/echo.py @@ -3,6 +3,7 @@ import datetime import socket import sys +import re # Block size is set to 8192 because thats usually the max header size BLOCK_SIZE = 8192 @@ -64,8 +65,10 @@ def build_request(first_chunk): lines = first_chunk.decode('utf-8', 'ignore').split('\r\n') h = {'request-line': lines[0]} i = 1 + header_kv = re.compile('(\w\S+)\s?:\s?(\S.*)') while i < len(lines[1:]) and lines[i] != '': - k, v = lines[i].split(': ') + m = header_kv.match(lines[i]) + k, v = m.group(1), m.group(2) h.update({k.lower(): v}) i += 1 r = {