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

Replacement of entire file #65

Closed
alberto-bottarini opened this issue Oct 11, 2012 · 2 comments · May be fixed by caputomarcos/mitmproxy#1
Closed

Replacement of entire file #65

alberto-bottarini opened this issue Oct 11, 2012 · 2 comments · May be fixed by caputomarcos/mitmproxy#1

Comments

@alberto-bottarini
Copy link

Hello, congrats for mitmproxy :)

It's possibile to completely replace a response body with a local file? I tried this way but I failed:

--replace=:site.css:.*:~/site.css

thanks

@cjneasbi
Copy link
Contributor

This is definitely possible but not from the command line. You'll have to write a script that hooks into the request or response callback functions. For example, say you wanted to replace the entire response for every response going to the proxy client. You could write a response call back such as:

def response(context, fl):
    flread = flow.FlowReader(open('/tmp/response.flow', 'r'))
    flstream = flread.stream()
    flreplace = flstream.next()
    fl.response._load_state(flreplace.response._get_state())

This will replace the entire state of the response with pre-recorded flow for every response. If you want to just override the content you can replace fl.response.content with some predetermed content. The only caveat is that the pre-recorded flow must be in the tnetstring format used by mitmproxy. You can either record the flow with mitmproxy or if you have a pcap file you can use mitmextract to extract and convert the flow.

Hope this helps.

@cortesi
Copy link
Member

cortesi commented Mar 2, 2013

cjneasbi's solution is the right way for now. Down the track, we may add some utility feature to make this easier, but I'm closing this issue for now.

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

Successfully merging a pull request may close this issue.

3 participants