From 9d5e59bdfa18c1c8a9c96bc946454e35a3f2420e Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 8 Aug 2020 00:16:24 +0200 Subject: [PATCH] standardize killed error message this is mostly a preparation for sans-io, where we detect kills using the presence of the error. --- mitmproxy/addons/clientplayback.py | 2 +- mitmproxy/flow.py | 5 +++-- mitmproxy/proxy/protocol/http2.py | 4 ++-- mitmproxy/proxy/server.py | 4 ++-- web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js | 2 +- web/src/js/components/FlowTable/FlowColumns.jsx | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/mitmproxy/addons/clientplayback.py b/mitmproxy/addons/clientplayback.py index 27f6ae280c..fc913c23e2 100644 --- a/mitmproxy/addons/clientplayback.py +++ b/mitmproxy/addons/clientplayback.py @@ -110,7 +110,7 @@ def replay(self, f): # pragma: no cover f.error = flow.Error(str(e)) self.channel.ask("error", f) except exceptions.Kill: - self.channel.tell("log", log.LogEntry("Connection killed", "info")) + self.channel.tell("log", log.LogEntry(flow.Error.KILLED_MESSAGE, "info")) except Exception as e: self.channel.tell("log", log.LogEntry(repr(e), "error")) finally: diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index 7044ac6c6a..21ce0eac3b 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -9,7 +9,6 @@ class Error(stateobject.StateObject): - """ An Error. @@ -24,6 +23,8 @@ class Error(stateobject.StateObject): timestamp: Seconds since the epoch """ + KILLED_MESSAGE = "Connection killed." + def __init__(self, msg: str, timestamp=None) -> None: """ @type msg: str @@ -156,7 +157,7 @@ def kill(self): """ Kill this request. """ - self.error = Error("Connection killed") + self.error = Error(Error.KILLED_MESSAGE) self.intercepted = False self.reply.kill(force=True) self.live = False diff --git a/mitmproxy/proxy/protocol/http2.py b/mitmproxy/proxy/protocol/http2.py index 71c30b322d..2f2197e1db 100644 --- a/mitmproxy/proxy/protocol/http2.py +++ b/mitmproxy/proxy/protocol/http2.py @@ -8,7 +8,7 @@ from h2 import events import queue -from mitmproxy import connections # noqa +from mitmproxy import connections, flow # noqa from mitmproxy import exceptions from mitmproxy import http from mitmproxy.proxy.protocol import base @@ -725,6 +725,6 @@ def run(self): except exceptions.SetServerNotAllowedException as e: # pragma: no cover self.log("Changing the Host server for HTTP/2 connections not allowed: {}".format(e), "info") except exceptions.Kill: # pragma: no cover - self.log("Connection killed", "info") + self.log(flow.Error.KILLED_MESSAGE, "info") self.kill() diff --git a/mitmproxy/proxy/server.py b/mitmproxy/proxy/server.py index 3688b677e9..2a534d4701 100644 --- a/mitmproxy/proxy/server.py +++ b/mitmproxy/proxy/server.py @@ -1,7 +1,7 @@ import sys import traceback -from mitmproxy import exceptions +from mitmproxy import exceptions, flow from mitmproxy import connections from mitmproxy import controller # noqa from mitmproxy import http @@ -120,7 +120,7 @@ def handle(self): root_layer = self.channel.ask("clientconnect", root_layer) root_layer() except exceptions.Kill: - self.log("Connection killed", "info") + self.log(flow.Error.KILLED_MESSAGE, "info") except exceptions.ProtocolException as e: if isinstance(e, exceptions.ClientHandshakeException): self.log( diff --git a/web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js b/web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js index f3373c0295..3622f3c1e5 100644 --- a/web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js +++ b/web/src/js/__tests__/components/FlowTable/FlowColumnsSpec.js @@ -69,7 +69,7 @@ describe('FlowColumns Components', () => { tree = pathColumn.toJSON() expect(tree).toMatchSnapshot() - tflow.error.msg = 'Connection killed' + tflow.error.msg = 'Connection killed.' tflow.intercepted = true pathColumn = renderer.create() tree = pathColumn.toJSON() diff --git a/web/src/js/components/FlowTable/FlowColumns.jsx b/web/src/js/components/FlowTable/FlowColumns.jsx index 64b8ac829c..7a4e112d6a 100644 --- a/web/src/js/components/FlowTable/FlowColumns.jsx +++ b/web/src/js/components/FlowTable/FlowColumns.jsx @@ -57,7 +57,7 @@ export function PathColumn({ flow }) { let err; if(flow.error){ - if (flow.error.msg === "Connection killed"){ + if (flow.error.msg === "Connection killed."){ err = } else { err =