Minor cleanups of proxy request handling.
This commit is contained in:
parent
f5e49ef598
commit
46ab6ed491
|
@ -51,6 +51,7 @@ class ProxyConfig:
|
||||||
self.transparent_proxy = transparent_proxy
|
self.transparent_proxy = transparent_proxy
|
||||||
self.authenticator = authenticator
|
self.authenticator = authenticator
|
||||||
|
|
||||||
|
|
||||||
class RequestReplayThread(threading.Thread):
|
class RequestReplayThread(threading.Thread):
|
||||||
def __init__(self, config, flow, masterq):
|
def __init__(self, config, flow, masterq):
|
||||||
self.config, self.flow, self.masterq = config, flow, masterq
|
self.config, self.flow, self.masterq = config, flow, masterq
|
||||||
|
@ -311,7 +312,7 @@ class ProxyHandler(tcp.BaseHandler):
|
||||||
line = self.get_line(self.rfile)
|
line = self.get_line(self.rfile)
|
||||||
if line == "":
|
if line == "":
|
||||||
return None
|
return None
|
||||||
if line.startswith("CONNECT"):
|
if http.parse_init_connect(line):
|
||||||
r = http.parse_init_connect(line)
|
r = http.parse_init_connect(line)
|
||||||
if not r:
|
if not r:
|
||||||
raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
|
raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
|
||||||
|
@ -332,14 +333,15 @@ class ProxyHandler(tcp.BaseHandler):
|
||||||
raise ProxyError(400, str(v))
|
raise ProxyError(400, str(v))
|
||||||
self.proxy_connect_state = (host, port, httpversion)
|
self.proxy_connect_state = (host, port, httpversion)
|
||||||
line = self.rfile.readline(line)
|
line = self.rfile.readline(line)
|
||||||
|
|
||||||
if self.proxy_connect_state:
|
if self.proxy_connect_state:
|
||||||
host, port, httpversion = self.proxy_connect_state
|
|
||||||
r = http.parse_init_http(line)
|
r = http.parse_init_http(line)
|
||||||
if not r:
|
if not r:
|
||||||
raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
|
raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
|
||||||
method, path, httpversion = r
|
method, path, httpversion = r
|
||||||
headers = self.read_headers(authenticate=False)
|
headers = self.read_headers(authenticate=False)
|
||||||
|
|
||||||
|
host, port, _ = self.proxy_connect_state
|
||||||
content = http.read_http_body_request(
|
content = http.read_http_body_request(
|
||||||
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
||||||
)
|
)
|
||||||
|
@ -348,7 +350,7 @@ class ProxyHandler(tcp.BaseHandler):
|
||||||
r = http.parse_init_proxy(line)
|
r = http.parse_init_proxy(line)
|
||||||
if not r:
|
if not r:
|
||||||
raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
|
raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
|
||||||
method, scheme, host, port, path, httpversion = http.parse_init_proxy(line)
|
method, scheme, host, port, path, httpversion = r
|
||||||
headers = self.read_headers(authenticate=True)
|
headers = self.read_headers(authenticate=True)
|
||||||
content = http.read_http_body_request(
|
content = http.read_http_body_request(
|
||||||
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
||||||
|
|
|
@ -4,7 +4,7 @@ from contextlib import contextmanager
|
||||||
from libmproxy import proxy, flow, controller, utils
|
from libmproxy import proxy, flow, controller, utils
|
||||||
from netlib import certutils
|
from netlib import certutils
|
||||||
import human_curl as hurl
|
import human_curl as hurl
|
||||||
import libpathod.test
|
import libpathod.test, libpathod.pathoc
|
||||||
|
|
||||||
def treq(conn=None):
|
def treq(conn=None):
|
||||||
if not conn:
|
if not conn:
|
||||||
|
@ -194,7 +194,6 @@ class ReverseProxTest(ProxTestBase):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def tmpdir(*args, **kwargs):
|
def tmpdir(*args, **kwargs):
|
||||||
orig_workdir = os.getcwd()
|
orig_workdir = os.getcwd()
|
||||||
|
@ -244,5 +243,6 @@ def raises(exc, obj, *args, **kwargs):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
raise AssertionError("No exception raised.")
|
raise AssertionError("No exception raised.")
|
||||||
|
|
||||||
|
|
||||||
test_data = utils.Data(__name__)
|
test_data = utils.Data(__name__)
|
||||||
|
|
Loading…
Reference in New Issue