From ddc08efde1a5132734f1f06481a97e484cc368e3 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 4 Jan 2013 14:23:52 +1300 Subject: [PATCH] Minor cleanup of http.parse_init* methods. --- netlib/http.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/netlib/http.py b/netlib/http.py index b71eb72db..3f730a1ae 100644 --- a/netlib/http.py +++ b/netlib/http.py @@ -166,36 +166,43 @@ def parse_http_protocol(s): return major, minor -def parse_init_connect(line): +def parse_init(line): try: method, url, protocol = string.split(line) except ValueError: return None - if method != 'CONNECT': + httpversion = parse_http_protocol(protocol) + if not httpversion: + return None + return method, url, httpversion + + +def parse_init_connect(line): + v = parse_init(line) + if not v: + return None + method, url, httpversion = v + + if method.upper() != 'CONNECT': return None try: host, port = url.split(":") except ValueError: return None port = int(port) - httpversion = parse_http_protocol(protocol) - if not httpversion: - return None return host, port, httpversion def parse_init_proxy(line): - try: - method, url, protocol = string.split(line) - except ValueError: + v = parse_init(line) + if not v: return None + method, url, httpversion = v + parts = parse_url(url) if not parts: return None scheme, host, port, path = parts - httpversion = parse_http_protocol(protocol) - if not httpversion: - return None return method, scheme, host, port, path, httpversion @@ -203,15 +210,13 @@ def parse_init_http(line): """ Returns (method, url, httpversion) """ - try: - method, url, protocol = string.split(line) - except ValueError: + v = parse_init(line) + if not v: return None + method, url, httpversion = v + if not (url.startswith("/") or url == "*"): return None - httpversion = parse_http_protocol(protocol) - if not httpversion: - return None return method, url, httpversion