Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying request.url impacted request.host #890

Closed
xuboying opened this issue Jan 22, 2016 · 2 comments
Closed

Modifying request.url impacted request.host #890

xuboying opened this issue Jan 22, 2016 · 2 comments

Comments

@xuboying
Copy link

mitmdump version:latest

I run the proxy with following command:

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

The proxy.py is like following:

#!/usr/bin/mitmdump
from __future__ import print_function
import re

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 will modify the url also
    print("DEBUG")

What I expect is to change the www.verycd.com to IP in url but keep the host field still using www.verycd.com, like following:

GET http://115.182.66.26/ HTTP/1.1
...
Host: www.verycd.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0

But the mitmproxy always change the url and host at the same time I got following which the server does not accept

GET http://115.182.66.26/ HTTP/1.1
...
Host: 115.182.66.26
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
@mhils
Copy link
Member

mhils commented Jan 22, 2016

Hi there,

this is currently done intentional - usually you want to modify both and people forget about the header. You can accomplish what you want by modifying the underlying data object directly (flow.request.data.host).

There are a few similar things in the request and response classes - for example, if you modify the message body, the content-length header will be adjusted accordingly. I'm not sure what's the best way for us to handle this.
@ALL: If you have any opinions on this behaviour, we'd love to hear them in the comments below.

@xuboying
Copy link
Author

Thanks a lot for the tip, it's working!!!
IMHO, content-length can be changed in the last step, or it will be reset by other changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants