【问题标题】:mitmproxy redirect request to localhost and set Host headermitmproxy 将请求重定向到 localhost 并设置 Host 标头
【发布时间】:2016-07-26 12:28:02
【问题描述】:

我在端口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: */*

【问题讨论】:

    标签: python curl reverse-proxy mitmproxy


    【解决方案1】:

    尝试:flow.request.headers["Host"] = ["mydomain.com"] 参考:https://github.com/mitmproxy/mitmproxy/blob/v0.9.2/examples/redirect_requests.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 2016-05-16
      • 2021-08-16
      • 2021-07-08
      相关资源
      最近更新 更多