From 73cb237a52625d5bbd213370e120d343d7ced397 Mon Sep 17 00:00:00 2001 From: "M. Yas. Davoodeh" <30480116+Davoodeh@users.noreply.github.com> Date: Thu, 25 Aug 2022 16:28:03 +0430 Subject: [PATCH] Add support for OWS in header-fields https://www.rfc-editor.org/rfc/rfc7230#section-3.2 > Each header field consists of a case-insensitive field name followed > by a colon (":"), optional leading whitespace, the field value, and > optional trailing whitespace. > > ``` > header-field = field-name ":" OWS field-value OWS > ``` Before this, the server would crash if the "optional" whitespace was missing. --- echo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/echo.py b/echo.py index ffaad5a..3e850da 100755 --- a/echo.py +++ b/echo.py @@ -65,7 +65,9 @@ def build_request(first_chunk): h = {'request-line': lines[0]} i = 1 while i < len(lines[1:]) and lines[i] != '': - k, v = lines[i].split(': ') + k, v = lines[i].split(":", 1) + if v[0] == " ": + v = v[1:] h.update({k.lower(): v}) i += 1 r = {