I've been working on a redirect script for mitmproxy running on a raspberry pi. I've looked at the post here and it didn't work. What happened was that the request was still going through to the original host url. After some changes, it would attempt to redirect to the new site but the status codes weren't reflecting that and it was still loading the resources of the original site. Make the path an empty string fixed this temporarily (it was no longer making calls for the resources by appending them on the new url). Also, since the original script did not work, I tried to make changes to reflect how a manual redirect works by adding "Location" to the headers for the response.
import mitmproxy
from mitmproxy.models import HTTPResponse
from netlib.http import Headers
def request(flow):
if flow.request.pretty_host.endswith("sojourncollege.com"):
mitmproxy.ctx.log( flow.request.path )
method = flow.request.path.split('/')[3].split('?')[0]
flow.request.host = "reddit.com"
flow.request.port = 80
flow.request.scheme = 'http'
flow.request.path = ''
if method == 'getjson':
flow.request.path=flow.request.path.replace(method,"getxml")
flow.request.headers["Host"] = "reddit.com"
flow.response.status_code = 302
flow.response.headers.append("Location")
mitmproxy.ctx.log(flow.response.headers)
flow.response.headers["Location"] = "reddit.com"
What is happening now is repeated 301 Get requests to http://reddit.com and a message of [no content]. If I load up the networking tab on chrome to view the request it is trying to reach "http://wwww.reddit.comhttp/1.1" and I have no idea why that is the case.
This is stuff that has seemed to work for others, I have no idea why it's not on the pi.