7

I am trying to setup mitmproxy so that I can make a request from my browser to https://{my-domain} and have it return a response from my local server running at http://localhost:3000 instead, but I cannot get the https request to reach my local server. I see the debugging statements from mitmproxy. Also, I can get it working for http traffic, but not for https.

I read the mitmproxy addon docs and api docs I've installed the cert and I can monitor https through the proxy.

I'm using Mitmproxy: 4.0.4 and Python: 3.7.4

This is my addon (local-redirect.py) and how I run mitmproxy:

from mitmproxy import ctx
import mitmproxy.http

class LocalRedirect:

  def __init__(self):
    print('Loaded redirect addon')

  def request(self, flow: mitmproxy.http.HTTPFlow):
    if 'my-actual-domain-here' in flow.request.pretty_host:
      ctx.log.info("pretty host is: %s" % flow.request.pretty_host)
      flow.request.host = "localhost"
      flow.request.port = 3000
      flow.request.scheme = 'http'

addons = [
  LocalRedirect()
]
$ mitmdump -s local-redirect.py | grep pretty

When I visit the url form my server, I see the logging statement, but my browser hangs on the request and there is no request made to my local server.

1 Answer 1

5

The above addon was fine, however my local server did not support HTTP2.

Using the --no-http2 option was a quick fix:

mitmproxy -s local-redirect.py --no-http2 --view-filter localhost

or

mitmdump -s local-redirect.py --no-http2 localhost
4
  • 1
    How did you ever had it work? For me, request isn't called during CONNECT requests (which Chrome sends for https:// URLs when using a proxy.) Nov 21, 2019 at 9:12
  • @IlyaSemenov mitm uses port 8080 by default. Did u install the cert and configure chrome correctly
    – J W
    Nov 22, 2019 at 11:31
  • 1
    Of course I did. The requests are coming through mitmdump (and the plugin), but request callback isn't called for https pages (it is for http pages). mitmproxy logs CONNECT (rather than HTTP GET) requests coming from Chrome when accessing https pages. Anyway, I switched to reverse proxy mode for my purposes. Nov 25, 2019 at 8:33
  • I have the same issue, but with an app I'm working on. So is this a thing that only happens when a proxy is active?
    – Paul
    May 30, 2022 at 21:22

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.