mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Adjust serve() API.
This commit is contained in:
parent
ac5aacce44
commit
f54ed69a35
@ -129,16 +129,16 @@ def _preview(is_request):
|
||||
|
||||
s = cStringIO.StringIO()
|
||||
args["pauses"] = r.preview_safe()
|
||||
|
||||
|
||||
c = app.config["pathod"].check_policy(r)
|
||||
if c:
|
||||
args["error"] = c
|
||||
return render(template, False, **args)
|
||||
|
||||
if is_request:
|
||||
r.serve(app.config["pathod"].request_settings, s, host="example.com")
|
||||
r.serve(s, app.config["pathod"].request_settings, host="example.com")
|
||||
else:
|
||||
r.serve(app.config["pathod"].request_settings, s)
|
||||
r.serve(s, app.config["pathod"].request_settings)
|
||||
|
||||
args["output"] = utils.escape_unprintables(s.getvalue())
|
||||
return render(template, False, **args)
|
||||
|
@ -605,7 +605,7 @@ class Message:
|
||||
actions.reverse()
|
||||
return [i.intermediate(settings) for i in actions]
|
||||
|
||||
def serve(self, settings, fp, request_host):
|
||||
def serve(self, fp, settings, request_host):
|
||||
"""
|
||||
fp: The file pointer to write to.
|
||||
|
||||
@ -733,8 +733,8 @@ class CraftedRequest(Request):
|
||||
for i in tokens:
|
||||
i.accept(settings, self)
|
||||
|
||||
def serve(self, settings, fp, host):
|
||||
d = Request.serve(self, settings, fp, host)
|
||||
def serve(self, fp, settings, host):
|
||||
d = Request.serve(self, fp, settings, host)
|
||||
d["spec"] = self.spec
|
||||
return d
|
||||
|
||||
@ -746,8 +746,8 @@ class CraftedResponse(Response):
|
||||
for i in tokens:
|
||||
i.accept(settings, self)
|
||||
|
||||
def serve(self, settings, fp):
|
||||
d = Response.serve(self, settings, fp, None)
|
||||
def serve(self, fp, settings):
|
||||
d = Response.serve(self, fp, settings, None)
|
||||
d["spec"] = self.spec
|
||||
return d
|
||||
|
||||
@ -759,11 +759,11 @@ class PathodErrorResponse(Response):
|
||||
self.msg = LiteralGenerator(msg)
|
||||
self.body = LiteralGenerator("pathod error: " + (body or msg))
|
||||
self.headers = [
|
||||
Header(ValueLiteral("Content-Type"), ValueLiteral("text/plain")),
|
||||
Header(ValueLiteral("Content-Type"), ValueLiteral("text/plain")),
|
||||
]
|
||||
|
||||
def serve(self, settings, fp):
|
||||
d = Response.serve(self, settings, fp, None)
|
||||
def serve(self, fp, settings):
|
||||
d = Response.serve(self, fp, settings, None)
|
||||
d["internal"] = True
|
||||
return d
|
||||
|
||||
|
@ -22,7 +22,7 @@ class Pathoc(tcp.TCPClient):
|
||||
language.FileAccessDenied.
|
||||
"""
|
||||
r = language.parse_request(self.settings, spec)
|
||||
ret = r.serve(self.settings, self.wfile, self.host)
|
||||
ret = r.serve(self.wfile, self.settings, self.host)
|
||||
self.wfile.flush()
|
||||
return http.read_response(self.rfile, r.method, None)
|
||||
|
||||
@ -68,7 +68,7 @@ class Pathoc(tcp.TCPClient):
|
||||
if showresp:
|
||||
self.rfile.start_log()
|
||||
try:
|
||||
req = r.serve(self.settings, self.wfile, self.host)
|
||||
req = r.serve(self.wfile, self.settings, self.host)
|
||||
self.wfile.flush()
|
||||
resp = http.read_response(self.rfile, r.method, None)
|
||||
except http.HttpError, v:
|
||||
|
@ -21,14 +21,14 @@ class PathodHandler(tcp.BaseHandler):
|
||||
c = self.server.check_policy(crafted)
|
||||
if c:
|
||||
err = language.PathodErrorResponse(c)
|
||||
err.serve(self.server.request_settings, self.wfile)
|
||||
err.serve(self.wfile, self.server.request_settings)
|
||||
log = dict(
|
||||
type = "error",
|
||||
msg = c
|
||||
)
|
||||
return False, log
|
||||
|
||||
response_log = crafted.serve(self.server.request_settings, self.wfile)
|
||||
response_log = crafted.serve(self.wfile, self.server.request_settings)
|
||||
log = dict(
|
||||
type = "crafted",
|
||||
request=request_log,
|
||||
@ -106,7 +106,7 @@ class PathodHandler(tcp.BaseHandler):
|
||||
return self.serve_crafted(crafted, request_log)
|
||||
elif self.server.noweb:
|
||||
crafted = language.PathodErrorResponse("Access Denied")
|
||||
crafted.serve(self.server.request_settings, self.wfile)
|
||||
crafted.serve(self.wfile, self.server.request_settings)
|
||||
return False, dict(type = "error", msg="Access denied: web interface disabled")
|
||||
else:
|
||||
self.info("app: %s %s"%(method, path))
|
||||
|
@ -206,7 +206,7 @@ class TestMisc:
|
||||
def test_internal_response(self):
|
||||
d = cStringIO.StringIO()
|
||||
s = language.PathodErrorResponse("foo")
|
||||
s.serve({}, d)
|
||||
s.serve(d, {})
|
||||
|
||||
|
||||
class Test_Action:
|
||||
@ -279,7 +279,7 @@ class TestInject:
|
||||
def test_serve(self):
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_response({}, "400:i0,'foo'")
|
||||
assert r.serve({}, s)
|
||||
assert r.serve(s, {})
|
||||
|
||||
def test_spec(self):
|
||||
e = language.InjectAt.expr()
|
||||
@ -344,7 +344,7 @@ class TestParseRequest:
|
||||
def test_render(self):
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_request({}, "GET:'/foo'")
|
||||
assert r.serve({}, s, "foo.com")
|
||||
assert r.serve(s, {}, "foo.com")
|
||||
|
||||
def test_str(self):
|
||||
r = language.parse_request({}, 'GET:"/foo"')
|
||||
@ -479,15 +479,15 @@ class TestWriteValues:
|
||||
def test_write_values_after(self):
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_response({}, "400:da")
|
||||
r.serve({}, s)
|
||||
r.serve(s, {})
|
||||
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_response({}, "400:pa,0")
|
||||
r.serve({}, s)
|
||||
r.serve(s, {})
|
||||
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_response({}, "400:ia,'xx'")
|
||||
r.serve({}, s)
|
||||
r.serve(s, {})
|
||||
assert s.getvalue().endswith('xx')
|
||||
|
||||
|
||||
@ -514,19 +514,19 @@ class TestResponse:
|
||||
def test_render(self):
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_response({}, "400'msg'")
|
||||
assert r.serve({}, s)
|
||||
assert r.serve(s, {})
|
||||
|
||||
def test_raw(self):
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_response({}, "400:b'foo'")
|
||||
r.serve({}, s)
|
||||
r.serve(s, {})
|
||||
v = s.getvalue()
|
||||
assert "Content-Length" in v
|
||||
assert "Date" in v
|
||||
|
||||
s = cStringIO.StringIO()
|
||||
r = language.parse_response({}, "400:b'foo':r")
|
||||
r.serve({}, s)
|
||||
r.serve(s, {})
|
||||
v = s.getvalue()
|
||||
assert not "Content-Length" in v
|
||||
assert not "Date" in v
|
||||
@ -534,7 +534,7 @@ class TestResponse:
|
||||
def test_length(self):
|
||||
def testlen(x):
|
||||
s = cStringIO.StringIO()
|
||||
x.serve({}, s)
|
||||
x.serve(s, {})
|
||||
assert x.length({}, None) == len(s.getvalue())
|
||||
testlen(language.parse_response({}, "400'msg'"))
|
||||
testlen(language.parse_response({}, "400'msg':h'foo'='bar'"))
|
||||
@ -544,7 +544,7 @@ class TestResponse:
|
||||
def testlen(x, actions):
|
||||
s = cStringIO.StringIO()
|
||||
m = x.maximum_length({}, None)
|
||||
x.serve({}, s)
|
||||
x.serve(s, {})
|
||||
assert m >= len(s.getvalue())
|
||||
|
||||
r = language.parse_response({}, "400'msg':b@100")
|
||||
|
Loading…
Reference in New Issue
Block a user