def async_mangle_request(self, request): # This function gets called to mangle/edit requests passed through the proxy retreq = request # Write original request to the temp file with tempfile.NamedTemporaryFile(delete=False) as tf: tfName = tf.name tf.write(request.full_request) # Have the console edit the file yield edit_file(tfName) # Create new mangled request from edited file with open(tfName, 'r') as f: text = f.read() os.remove(tfName) # Check if dropped if text == '': pappyproxy.proxy.log('Request dropped!') defer.returnValue(None) mangled_req = Request(text, update_content_length=True) mangled_req._host = request.host mangled_req.port = request.port mangled_req.is_ssl = request.is_ssl # Check if it changed if mangled_req.full_request != request.full_request: retreq = mangled_req defer.returnValue(retreq)
def http_request(): req = Request('GET / HTTP/1.1\r\n\r\n') req.host = 'www.foo.faketld' req.port = '1337' req.is_ssl = True req.reqid = 123 rsp = Response('HTTP/1.1 200 OK\r\n\r\n') req.response = rsp return req