websocket: change cmdline option

This commit is contained in:
Thomas Kriechbaumer 2016-11-13 21:26:50 +01:00
parent aaa4ccc284
commit 4beb693c9c
4 changed files with 14 additions and 13 deletions

View File

@ -73,7 +73,7 @@ class Options(optmanager.OptManager):
mode: str = "regular",
no_upstream_cert: bool = False,
rawtcp: bool = False,
websockets: bool = False,
websocket: bool = True,
spoof_source_address: bool = False,
upstream_server: Optional[str] = None,
upstream_auth: Optional[str] = None,
@ -136,7 +136,7 @@ class Options(optmanager.OptManager):
self.mode = mode
self.no_upstream_cert = no_upstream_cert
self.rawtcp = rawtcp
self.websockets = websockets
self.websocket = websocket
self.spoof_source_address = spoof_source_address
self.upstream_server = upstream_server
self.upstream_auth = upstream_auth

View File

@ -398,13 +398,13 @@ class HttpLayer(base.Layer):
websockets.check_handshake(f.request.headers) and
websockets.check_handshake(f.response.headers)
)
if is_websocket and not self.config.options.websockets:
if is_websocket and not self.config.options.websocket:
self.log(
"Client requested WebSocket connection, but the protocol is disabled.",
"info"
)
if is_websocket and self.config.options.websockets:
if is_websocket and self.config.options.websocket:
layer = WebSocketLayer(self, f)
else:
layer = self.ctx.next_layer(self)

View File

@ -256,7 +256,7 @@ def get_common_options(args):
no_upstream_cert = args.no_upstream_cert,
spoof_source_address = args.spoof_source_address,
rawtcp = args.rawtcp,
websockets = args.websockets,
websocket = args.websocket,
upstream_server = upstream_server,
upstream_auth = args.upstream_auth,
ssl_version_client = args.ssl_version_client,
@ -459,6 +459,12 @@ def proxy_options(parser):
If your OpenSSL version supports ALPN, HTTP/2 is enabled by default.
"""
)
group.add_argument(
"--no-websocket",
action="store_false", dest="websocket",
help="Explicitly disable WebSocket support."
)
parser.add_argument(
"--upstream-auth",
action="store", dest="upstream_auth", default=None,
@ -468,6 +474,7 @@ def proxy_options(parser):
requests. Format: username:password
"""
)
rawtcp = group.add_mutually_exclusive_group()
rawtcp.add_argument("--raw-tcp", action="store_true", dest="rawtcp")
rawtcp.add_argument("--no-raw-tcp", action="store_false", dest="rawtcp",
@ -475,13 +482,7 @@ def proxy_options(parser):
"Disabled by default. "
"Default value will change in a future version."
)
websockets = group.add_mutually_exclusive_group()
websockets.add_argument("--websockets", action="store_true", dest="websockets")
websockets.add_argument("--no-websockets", action="store_false", dest="websockets",
help="Explicitly enable/disable experimental WebSocket support. "
"Disabled by default as messages are only printed to the event log and not retained. "
"Default value will change in a future version."
)
group.add_argument(
"--spoof-source-address",
action="store_true", dest="spoof_source_address",

View File

@ -64,7 +64,7 @@ class _WebSocketTestBase:
listen_port=0,
no_upstream_cert=False,
ssl_insecure=True,
websockets=True,
websocket=True,
)
opts.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy")
return opts