当使用 mitmproxy 和以下代码时,我尝试返回自定义响应
from libmproxy.models import HTTPResponse
from netlib.http import Headers
def request(context, flow):
if flow.request.pretty_url.endswith("example.com/index.php"):
resp = HTTPResponse(
[1, 1], 200, "OK",
Headers(Content_Type="text/html"),
"<html><body>hello world</body></html>")
flow.reply(resp)
Run Code Online (Sandbox Code Playgroud)
但结果并不符合预期,在浏览器中它显示为 http 状态代码、标头和正文为明文
[1,1] 200 OK
Content-Type: text/html
<html><body>hello world</body></html>
Run Code Online (Sandbox Code Playgroud)
我怎样才能将它作为实际的“http”响应返回,以便chrome将其渲染为html?
mitmproxy ×1