Repository navigation
Closed
Description
Steps to reproduce the problem:
- 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()
]- 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
Reacted by Lucas Ramage
Activity
Support float type in mitmweb
gcmurphy commentedon May 25, 2018
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"
gcmurphy commentedon Jul 30, 2018
@mhils thoughts on how I should proceed given the above?
mhils commentedon Jul 30, 2018
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:
mitmweb: support float options in the Options editor
mitmweb: support float options in the Options editor
mitmweb: support float options in the Options editor (mitmproxy#8447)
mitmweb: support float options in the Options editor (mitmproxy#8447)