From 28db0bd9108bc8ef056506ff11a291ac4e052fd6 Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Sun, 11 Oct 2015 16:39:22 -0400 Subject: [PATCH] Parse request line without using regular expressions. Split the request line by spaces. This allows any character to be used in the request URI. --- rester/parse.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/rester/parse.py b/rester/parse.py index 2011c6e..9ee03a0 100644 --- a/rester/parse.py +++ b/rester/parse.py @@ -14,19 +14,24 @@ from urlparse import parse_qs from urllib import quote -RE_METHOD = """(?P[A-Z]+)""" -RE_URI = """(?P[a-zA-Z0-9\-\/\.\_\:\?\#\[\]\@\!\$\&\=]+)""" - def _read_request_line_dict(line): - # Return a dicionary containing information about the request. - m = re.search(RE_METHOD + "\s+" + RE_URI, line) - if m: - return m.groupdict() - m = re.search(RE_URI, line) - if m: - return m.groupdict() - return None + """Return a dict containing the method and uri for a request line""" + + # Split the line into words. + words = line.split(" ") + method = "GET" + # If the line contains only one word, assume the line is the URI. + if len(words) == 1: + uri = words[0] + else: + method = words[0] + uri = words[1] + + return { + "method": method, + "uri": uri + } class RequestParser: