我在端口8181
上本地运行http服务器。我在我的设备上配置了mitmproxy
,现在我需要将来自特定域的请求转发到我的本地服务器实例。所以我正在使用here描述的请求重定向示例脚本:
def request(flow):
# pretty_host takes the "Host" header of the request into account,
# which is useful in transparent mode where we usually only have the IP
# otherwise.
# Method 2: Redirect the request to a different server
if flow.request.pretty_host.endswith("mydomain.com"):
flow.request.headers["Host"] = flow.request.headers
flow.request.host = "localhost"
flow.request.port = 8181
flow.request.scheme = 'http'
这有效,但我需要将Host
标头设置为原始请求主机,因此我按照here所述的添加标头示例执行
flow.request.headers["Host"] = flow.request.headers
但在mitmproxy
时,我无法在请求中看到此标头集,而且我在localhost
服务器日志中找不到它。
所以我想做的就像cURL
curl -b c -c c "http://localhost:8181/something" -H "Host: mydomain.com"
至少要有
所需的请求标头* Trying ::1...
* Connected to localhost (::1) port 8181 (#0)
> GET /something HTTP/1.1
> Host:mydomain.com
> User-Agent: curl/7.43.0
> Accept: */*
答案 0 :(得分:1)
尝试:flow.request.headers [“Host”] = [“mydomain.com”] 参考:https://github.com/mitmproxy/mitmproxy/blob/v0.9.2/examples/redirect_requests.py