2016-07-26 128 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: */* 

回答

相關問題