mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Add a --nohang flag that turns off pauses in response generation.
This commit is contained in:
parent
b879890412
commit
3e158211a8
@ -117,9 +117,9 @@ def _preview(is_request):
|
||||
args["pauses"] = r.preview_safe()
|
||||
|
||||
if is_request:
|
||||
r.serve(s, check=app.config["pathod"].check_size, host="example.com")
|
||||
r.serve(s, check=app.config["pathod"].check_policy, host="example.com")
|
||||
else:
|
||||
r.serve(s, check=app.config["pathod"].check_size)
|
||||
r.serve(s, check=app.config["pathod"].check_policy)
|
||||
|
||||
args["output"] = utils.escape_unprintables(s.getvalue())
|
||||
return render(template, **args)
|
||||
|
@ -19,7 +19,7 @@ class PathodHandler(tcp.BaseHandler):
|
||||
self.sni = connection.get_servername()
|
||||
|
||||
def serve_crafted(self, crafted, request_log):
|
||||
response_log = crafted.serve(self.wfile, self.server.check_size)
|
||||
response_log = crafted.serve(self.wfile, self.server.check_policy)
|
||||
self.server.add_log(
|
||||
dict(
|
||||
type = "crafted",
|
||||
@ -97,7 +97,7 @@ class PathodHandler(tcp.BaseHandler):
|
||||
return self.serve_crafted(crafted, request_log)
|
||||
elif self.server.noweb:
|
||||
crafted = rparse.PathodErrorResponse("Access Denied")
|
||||
crafted.serve(self.wfile, self.server.check_size)
|
||||
crafted.serve(self.wfile, self.server.check_policy)
|
||||
return False
|
||||
else:
|
||||
cc = wsgi.ClientConn(self.client_address)
|
||||
@ -150,7 +150,7 @@ class Pathod(tcp.TCPServer):
|
||||
LOGBUF = 500
|
||||
def __init__( self,
|
||||
addr, ssloptions=None, craftanchor="/p/", staticdir=None, anchors=None,
|
||||
sizelimit=None, noweb=False, nocraft=False, noapi=False
|
||||
sizelimit=None, noweb=False, nocraft=False, noapi=False, nohang=False
|
||||
):
|
||||
"""
|
||||
addr: (address, port) tuple. If port is 0, a free port will be
|
||||
@ -160,13 +160,16 @@ class Pathod(tcp.TCPServer):
|
||||
staticdir: path to a directory of static resources, or None.
|
||||
anchors: A list of (regex, spec) tuples, or None.
|
||||
sizelimit: Limit size of served data.
|
||||
nocraft: Disable response crafting.
|
||||
noapi: Disable the API.
|
||||
nohang: Disable pauses.
|
||||
"""
|
||||
tcp.TCPServer.__init__(self, addr)
|
||||
self.ssloptions = ssloptions
|
||||
self.staticdir = staticdir
|
||||
self.craftanchor = craftanchor
|
||||
self.sizelimit = sizelimit
|
||||
self.noweb, self.nocraft, self.noapi = noweb, nocraft, noapi
|
||||
self.noweb, self.nocraft, self.noapi, self.nohang = noweb, nocraft, noapi, nohang
|
||||
if not noapi:
|
||||
app.api()
|
||||
self.app = app.app
|
||||
@ -186,12 +189,14 @@ class Pathod(tcp.TCPServer):
|
||||
raise PathodError("Invalid page spec in anchor: '%s', %s"%(i[1], str(v)))
|
||||
self.anchors.append((arex, aresp))
|
||||
|
||||
def check_size(self, req, actions):
|
||||
def check_policy(self, req, actions):
|
||||
"""
|
||||
A policy check that verifies the request size is withing limits.
|
||||
"""
|
||||
if self.sizelimit and req.effective_length(actions) > self.sizelimit:
|
||||
return "Response too large."
|
||||
if self.nohang and any([i[1] == "pause" for i in actions]):
|
||||
return "Pauses have been disabled."
|
||||
return False
|
||||
|
||||
@property
|
||||
|
7
pathod
7
pathod
@ -34,6 +34,10 @@ if __name__ == "__main__":
|
||||
"--noapi", dest='noapi', default=False, action="store_true",
|
||||
help='Disable API.'
|
||||
)
|
||||
parser.add_argument(
|
||||
"--nohang", dest='nohang', default=False, action="store_true",
|
||||
help='Disable pauses during crafted response generation.'
|
||||
)
|
||||
parser.add_argument(
|
||||
"--noweb", dest='noweb', default=False, action="store_true",
|
||||
help='Disable both web interface and API.'
|
||||
@ -100,7 +104,8 @@ if __name__ == "__main__":
|
||||
sizelimit = sizelimit,
|
||||
noweb = args.noweb,
|
||||
nocraft = args.nocraft,
|
||||
noapi = args.noapi
|
||||
noapi = args.noapi,
|
||||
nohang = args.nohang
|
||||
)
|
||||
except pathod.PathodError, v:
|
||||
parser.error(str(v))
|
||||
|
@ -43,6 +43,15 @@ class TestNoApi(tutils.DaemonTests):
|
||||
assert not "Log" in r.content
|
||||
|
||||
|
||||
class TestNohang(tutils.DaemonTests):
|
||||
nohang = True
|
||||
def test_nohang(self):
|
||||
r = self.get("200:p0,0")
|
||||
assert r.status_code == 800
|
||||
l = self.d.log()[0]
|
||||
assert "Pauses have been disabled" in l["response"]["error"]
|
||||
|
||||
|
||||
class CommonTests(tutils.DaemonTests):
|
||||
def test_sizelimit(self):
|
||||
r = self.get("200:b@1g")
|
||||
|
@ -6,6 +6,7 @@ import requests
|
||||
class DaemonTests:
|
||||
noweb = False
|
||||
noapi = False
|
||||
nohang = False
|
||||
ssl = False
|
||||
@classmethod
|
||||
def setUpAll(self):
|
||||
@ -15,7 +16,8 @@ class DaemonTests:
|
||||
ssl = self.ssl,
|
||||
sizelimit=1*1024*1024,
|
||||
noweb = self.noweb,
|
||||
noapi = self.noapi
|
||||
noapi = self.noapi,
|
||||
nohang = self.nohang
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user