from mitmproxy import http def request(flow: http.HTTPFlow) -> None: # Check if the content length is 0 and request is a SOAP message if flow.request.headers.get("content-length", "") == "0" and "soapenv:Envelope" in flow.request.content.decode("utf-8"): # Create SOAP response soap_response = ''' 2 1 ''' # Modify the response to be SOAP format flow.response = http.HTTPResponse.make( 200, # HTTP status code soap_response.encode("utf-8"), # Response content in SOAP format {"Content-Type": "application/xml"} # Response headers ) addons = [ # Add the request handler http.HTTPFlowHook(request) ]