python - Modifying request.url without changing request.host -


i'm using mitmproxy python http proxy

i run proxy following command:

mitmdump -s proxy.py -u http://upstreamproxy 

the proxy.py following:

#!/usr/bin/mitmdump __future__ import print_function import pprint import datetime import os import re   pp = pprint.prettyprinter(indent=4)  def request(context, flow):     print("debug")     oldhost = flow.request.host     flow.request.url = re.sub(r"www.verycd.com",r"115.182.66.26",flow.request.url)     # flow.request.host = oldhost   #<---this modify url     print("debug") 

what expect change www.verycd.com ip in url keep host field still using www.verycd.com, following:

get http://115.182.66.26/ http/1.1 te: deflate,gzip;q=0.3 connection: te, close accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-encoding: gzip, deflate accept-language: zh,en-us;q=0.5 host: www.verycd.com user-agent: mozilla/5.0 (windows nt 6.1; wow64; rv:43.0) gecko/20100101 firefox/43.0 

but mitmproxy change url , host @ same time got following server not accept

get http://115.182.66.26/ http/1.1 te: deflate,gzip;q=0.3 connection: te, close accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-encoding: gzip, deflate accept-language: zh,en-us;q=0.5 host: 115.182.66.26 user-agent: mozilla/5.0 (windows nt 6.1; wow64; rv:43.0) gecko/20100101 firefox/43.0 

already answered project owner

https://github.com/mitmproxy/mitmproxy/issues/890


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -