2016-07-26 1015 views
1

我在端口8181本地运行一个HTTP服务器。我在我的设备上配置了我的mitmproxy,现在我需要将来自特定域的请求转发到本地服务器实例。所以我使用请求重定向示例脚本描述heremitmproxy重定向请求本地主机和设置主机标头

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服务器日志。

所以,我想以此来至少有需要的请求头像

* Trying ::1... 
* Connected to localhost (::1) port 8181 (#0) 
> GET /something HTTP/1.1 
> Host:mydomain.com 
> User-Agent: curl/7.43.0 
> Accept: */* 

回答

相关问题