def test_decoded(): r = tutils.treq() assert r.content == "content" assert not r.headers["content-encoding"] r.encode("gzip") assert r.headers["content-encoding"] assert r.content != "content" with flow.decoded(r): assert not r.headers["content-encoding"] assert r.content == "content" assert r.headers["content-encoding"] assert r.content != "content" with flow.decoded(r): r.content = "foo" assert r.content != "foo" r.decode() assert r.content == "foo"
def response(context, flow): with decoded(flow.response): clamd_result = clamd.scan_stream(flow.response.content) if clamd_result: print "Virus detected: ",clamd_result flow.response.content = "HoneyProxy has detected a virus and stopped this page from loading: %s" % str(clamd_result["stream"]) flow.response.headers["Content-Length"] = [str(len(flow.response.content))] flow.response.headers["Content-Type"] = ["text/html"] del flow.response.headers["Content-Disposition"] del flow.response.headers["Content-Encoding"] flow.response.code = 403 flow.response.msg = "Forbidden"
def response(context, flow): with decoded(flow.response): clamd_result = clamd.scan_stream(flow.response.content) if clamd_result: print "Virus detected: ", clamd_result flow.response.content = "HoneyProxy has detected a virus and stopped this page from loading: %s" % str( clamd_result["stream"]) flow.response.headers["Content-Length"] = [ str(len(flow.response.content)) ] flow.response.headers["Content-Type"] = ["text/html"] del flow.response.headers["Content-Disposition"] del flow.response.headers["Content-Encoding"] flow.response.code = 403 flow.response.msg = "Forbidden"