Skip to content

mitmweb - Does not support same addon options types as mitmproxy #3144

Closed

Description

@gcmurphy
Steps to reproduce the problem:
  1. Given this addon:
from mitmproxy import http

class Reproducer:
    def load(self, loader):
        loader.add_option(name="this_will_break_things",
                          typespec=float,
                          default=0.42,
                          help="Float options not supported by mitmweb")

    def response(self, flow: http.HTTPFlow) -> None:
        flow.response.status_code = 400
        flow.response.content = b'opps'

addons = [
    Reproducer()
]
  1. Start mitmweb with the addon:
(mitmproxy-h3iGBSQq) ➜  mitmproxy git:(mitmproxy) ✗ mitmweb -s reproducer.py
Web server listening at http://127.0.0.1:8081/
Loading script reproducer.py
Proxy server listening at http://*:8080
ERROR:tornado.application:Uncaught exception GET /options.json (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:8081', method='GET', uri='/options.json', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "/Users/grantmurphy/.local/share/virtualenvs/mitmproxy-h3iGBSQq/lib/python3.6/site-packages/tornado/web.py", line 1541, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "/Users/grantmurphy/.local/share/virtualenvs/mitmproxy-h3iGBSQq/lib/python3.6/site-packages/mitmproxy/tools/web/app.py", line 447, in get
    self.write(optmanager.dump_dicts(self.master.options))
  File "/Users/grantmurphy/.local/share/virtualenvs/mitmproxy-h3iGBSQq/lib/python3.6/site-packages/mitmproxy/optmanager.py", line 463, in dump_dicts
    t = typecheck.typespec_to_str(o.typespec)
  File "/Users/grantmurphy/.local/share/virtualenvs/mitmproxy-h3iGBSQq/lib/python3.6/site-packages/mitmproxy/utils/typecheck.py", line 85, in typespec_to_str
    raise NotImplementedError
NotImplementedError
ERROR:tornado.access:500 GET /options.json (127.0.0.1) 4.66ms
^C%                                                                                                                                                                                                         
Any other comments? What have you tried so far?

Replacing the type of the option with str resolves the problem, however this does not reflect the documented supported types

This doesn't break mitmproxy however, only mitmweb.

System information
(mitmproxy-h3iGBSQq) ➜  mitmproxy git:(mitmproxy) ✗ mitmweb --version
Mitmproxy: 4.0.1 
Python:    3.6.5
OpenSSL:   OpenSSL 1.1.0h  27 Mar 2018
Platform:  Darwin-17.5.0-x86_64-i386-64bit

Activity

  1. added a commit that references this issue on May 25, 2018
  2. gcmurphy commented on May 25, 2018

    @gcmurphy
    Author

    gcmurphy@f61399a is a partial fix for this, however the interaction between .js and .py is broken for whole numbers. E.g. javascript: parseFloat(1.0) -> 1 -> json -> python: "this is an int not a float"

    screen shot 2018-05-25 at 1 32 55 pm

  3. gcmurphy commented on Jul 30, 2018

    @gcmurphy
    Author

    @mhils thoughts on how I should proceed given the above?

  4. mhils commented on Jul 30, 2018

    @mhils
    Member

    Thanks for pushing this @gcmurphy. :) I think your proposed approach is correct here - JS will provide us with JSON ints only, so we should definitely handle them gracefully in the backend. Given that this is JS-specific, how do you feel about manually handling this here? Getting the expected type is a bit tricky, but you should be able to do something like this:

    for name, opt in self.master.options.items():
        if name in json and opt.typespec == ...:
            # ...
  5. added a commit that references this issue on Sep 24, 2026
    977d2c2
  6. added a commit that references this issue on Oct 1, 2026
    fe2c328
  7. added a commit that references this issue on Oct 1, 2026
    3a5deb0
  8. added a commit that references this issue on Oct 31, 2026
    a1fe30d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions