mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
This commit is contained in:
parent
380ff50e57
commit
d6465b907f
@ -131,7 +131,7 @@ class HTTPMode(enum.Enum):
|
||||
# At this point, we see only a subset of the proxy modes
|
||||
MODE_REQUEST_FORMS = {
|
||||
HTTPMode.regular: ("authority", "absolute"),
|
||||
HTTPMode.transparent: ("relative"),
|
||||
HTTPMode.transparent: ("relative",),
|
||||
HTTPMode.upstream: ("authority", "absolute"),
|
||||
}
|
||||
|
||||
@ -143,9 +143,16 @@ def validate_request_form(mode, request):
|
||||
)
|
||||
allowed_request_forms = MODE_REQUEST_FORMS[mode]
|
||||
if request.first_line_format not in allowed_request_forms:
|
||||
err_message = "Invalid HTTP request form (expected: %s, got: %s)" % (
|
||||
" or ".join(allowed_request_forms), request.first_line_format
|
||||
)
|
||||
if mode == HTTPMode.transparent:
|
||||
err_message = (
|
||||
"Mitmproxy received an {} request even though it is not running in regular mode. "
|
||||
"This usually indicates a misconfiguration, please see "
|
||||
"http://docs.mitmproxy.org/en/stable/modes.html for details."
|
||||
).format("HTTP CONNECT" if request.first_line_format == "authority" else "absolute-form")
|
||||
else:
|
||||
err_message = "Invalid HTTP request form (expected: %s, got: %s)" % (
|
||||
" or ".join(allowed_request_forms), request.first_line_format
|
||||
)
|
||||
raise exceptions.HttpException(err_message)
|
||||
|
||||
|
||||
|
@ -30,6 +30,16 @@ class TestInvalidRequests(tservers.HTTPProxyTest):
|
||||
assert b"Invalid HTTP request form" in r.content
|
||||
|
||||
|
||||
class TestProxyMisconfiguration(tservers.TransparentProxyTest):
|
||||
|
||||
def test_absolute_request(self):
|
||||
p = self.pathoc()
|
||||
with p.connect():
|
||||
r = p.request("get:'http://localhost:%d/p/200'" % self.server.port)
|
||||
assert r.status_code == 400
|
||||
assert b"misconfiguration" in r.content
|
||||
|
||||
|
||||
class TestExpectHeader(tservers.HTTPProxyTest):
|
||||
|
||||
def test_simple(self):
|
||||
|
Loading…
Reference in New Issue
Block a user