Minor cleanup of http.parse_init* methods.

This commit is contained in:
Aldo Cortesi 2013-01-04 14:23:52 +13:00
parent bb317051a4
commit ddc08efde1
1 changed files with 22 additions and 17 deletions

View File

@ -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