mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Refactor rparse.InternalResponse -> rparse.PathodErrorResponse
This commit is contained in:
parent
1c45f5b05c
commit
5283bb2507
@ -67,15 +67,12 @@ class PathodHandler(tcp.BaseHandler):
|
||||
try:
|
||||
crafted = rparse.parse_response(self.server.request_settings, spec)
|
||||
except rparse.ParseException, v:
|
||||
crafted = rparse.InternalResponse(
|
||||
800,
|
||||
crafted = rparse.PathodErrorResponse(
|
||||
"Parse Error",
|
||||
"Error parsing response spec: %s\n"%v.msg + v.marked()
|
||||
)
|
||||
except rparse.FileAccessDenied:
|
||||
crafted = rparse.InternalResponse(
|
||||
800,
|
||||
"Access Denied"
|
||||
)
|
||||
crafted = rparse.PathodErrorResponse("Access Denied")
|
||||
|
||||
request_log = dict(
|
||||
path = path,
|
||||
|
@ -570,10 +570,7 @@ class Message:
|
||||
if check:
|
||||
ret = check(self, actions)
|
||||
if ret:
|
||||
err = InternalResponse(
|
||||
800,
|
||||
ret
|
||||
)
|
||||
err = PathodErrorResponse(ret)
|
||||
err.serve(fp)
|
||||
return dict(
|
||||
disconnect = True,
|
||||
@ -706,12 +703,12 @@ class CraftedResponse(Response):
|
||||
return d
|
||||
|
||||
|
||||
class InternalResponse(Response):
|
||||
def __init__(self, code, body):
|
||||
class PathodErrorResponse(Response):
|
||||
def __init__(self, msg, body=None):
|
||||
Response.__init__(self)
|
||||
self.code = code
|
||||
self.msg = LiteralGenerator(http_status.RESPONSES.get(code, "Unknown error"))
|
||||
self.body = LiteralGenerator(body)
|
||||
self.code = 800
|
||||
self.msg = LiteralGenerator(msg)
|
||||
self.body = LiteralGenerator(body or msg)
|
||||
self.headers = [
|
||||
(
|
||||
LiteralGenerator("Content-Type"),
|
||||
|
@ -155,7 +155,7 @@ class TestMisc:
|
||||
|
||||
def test_internal_response(self):
|
||||
d = cStringIO.StringIO()
|
||||
s = rparse.InternalResponse(400, "foo")
|
||||
s = rparse.PathodErrorResponse("foo")
|
||||
s.serve(d)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user