aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/builtins/script.py4
-rw-r--r--mitmproxy/console/master.py18
-rw-r--r--mitmproxy/console/signals.py1
-rw-r--r--mitmproxy/dump.py1
-rw-r--r--mitmproxy/main.py3
-rw-r--r--mitmproxy/web/static/images/favicon.icobin0 -> 365133 bytes
-rw-r--r--mitmproxy/web/templates/index.html3
-rw-r--r--web/package.json1
-rw-r--r--web/src/images/favicon.icobin0 -> 365133 bytes
-rw-r--r--web/src/js/__tests__/ducks/flowViewSpec.js (renamed from web/src/js/__tests__/ducks/flowView.js)0
-rw-r--r--web/src/js/__tests__/ducks/flowsSpec.js (renamed from web/src/js/__tests__/ducks/flows.js)0
-rw-r--r--web/src/js/__tests__/ducks/ui/headerSpec.js (renamed from web/src/js/__tests__/ducks/ui.js)10
-rw-r--r--web/src/js/__tests__/ducks/utils/listSpec.js (renamed from web/src/js/__tests__/ducks/utils/list.js)0
-rw-r--r--web/src/js/__tests__/ducks/utils/viewSpec.js (renamed from web/src/js/__tests__/ducks/utils/view.js)6
-rwxr-xr-xweb/src/js/ducks/utils/view.js54
-rw-r--r--web/src/templates/index.html3
16 files changed, 79 insertions, 25 deletions
diff --git a/mitmproxy/builtins/script.py b/mitmproxy/builtins/script.py
index c960dd1c..ae1d1b91 100644
--- a/mitmproxy/builtins/script.py
+++ b/mitmproxy/builtins/script.py
@@ -61,13 +61,13 @@ def scriptenv(path, args):
try:
yield
except Exception:
- _, _, tb = sys.exc_info()
+ etype, value, tb = sys.exc_info()
scriptdir = os.path.dirname(os.path.abspath(path))
for i, s in enumerate(reversed(traceback.extract_tb(tb))):
tb = tb.tb_next
if not os.path.abspath(s[0]).startswith(scriptdir):
break
- ctx.log.error("Script error: %s" % "".join(traceback.format_tb(tb)))
+ ctx.log.error("Script error: %s" % "".join(traceback.format_exception(etype, value, tb)))
finally:
sys.argv = oldargs
sys.path.pop()
diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py
index 03ec8b63..9a9addc5 100644
--- a/mitmproxy/console/master.py
+++ b/mitmproxy/console/master.py
@@ -258,6 +258,7 @@ class ConsoleMaster(flow.FlowMaster):
signals.call_in.connect(self.sig_call_in)
signals.pop_view_state.connect(self.sig_pop_view_state)
+ signals.replace_view_state.connect(self.sig_replace_view_state)
signals.push_view_state.connect(self.sig_push_view_state)
signals.sig_add_log.connect(self.sig_add_log)
self.addons.add(options, *builtins.default_addons())
@@ -296,7 +297,19 @@ class ConsoleMaster(flow.FlowMaster):
return callback(*args)
self.loop.set_alarm_in(seconds, cb)
+ def sig_replace_view_state(self, sender):
+ """
+ A view has been pushed onto the stack, and is intended to replace
+ the current view rather tha creating a new stack entry.
+ """
+ if len(self.view_stack) > 1:
+ del self.view_stack[1]
+
def sig_pop_view_state(self, sender):
+ """
+ Pop the top view off the view stack. If no more views will be left
+ after this, prompt for exit.
+ """
if len(self.view_stack) > 1:
self.view_stack.pop()
self.loop.widget = self.view_stack[-1]
@@ -312,6 +325,9 @@ class ConsoleMaster(flow.FlowMaster):
)
def sig_push_view_state(self, sender, window):
+ """
+ Push a new view onto the view stack.
+ """
self.view_stack.append(window)
self.loop.widget = window
self.loop.draw_screen()
@@ -352,8 +368,8 @@ class ConsoleMaster(flow.FlowMaster):
def toggle_eventlog(self):
self.options.eventlog = not self.options.eventlog
- signals.pop_view_state.send(self)
self.view_flowlist()
+ signals.replace_view_state.send(self)
def _readflows(self, path):
"""
diff --git a/mitmproxy/console/signals.py b/mitmproxy/console/signals.py
index 97507834..93eb399f 100644
--- a/mitmproxy/console/signals.py
+++ b/mitmproxy/console/signals.py
@@ -43,3 +43,4 @@ flowlist_change = blinker.Signal()
# Pop and push view state onto a stack
pop_view_state = blinker.Signal()
push_view_state = blinker.Signal()
+replace_view_state = blinker.Signal()
diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py
index 83f44d87..e59fd23e 100644
--- a/mitmproxy/dump.py
+++ b/mitmproxy/dump.py
@@ -118,5 +118,6 @@ class DumpMaster(flow.FlowMaster):
def run(self): # pragma: no cover
if self.options.rfile and not self.options.keepserving:
+ self.addons.done()
return
super(DumpMaster, self).run()
diff --git a/mitmproxy/main.py b/mitmproxy/main.py
index 6d44108e..464c3897 100644
--- a/mitmproxy/main.py
+++ b/mitmproxy/main.py
@@ -92,6 +92,7 @@ def mitmdump(args=None): # pragma: no cover
if args.quiet:
args.flow_detail = 0
+ master = None
try:
dump_options = dump.Options(**cmdline.get_common_options(args))
dump_options.flow_detail = args.flow_detail
@@ -110,7 +111,7 @@ def mitmdump(args=None): # pragma: no cover
sys.exit(1)
except (KeyboardInterrupt, _thread.error):
pass
- if master.has_errored:
+ if master is None or master.has_errored:
print("mitmdump: errors occurred during run", file=sys.stderr)
sys.exit(1)
diff --git a/mitmproxy/web/static/images/favicon.ico b/mitmproxy/web/static/images/favicon.ico
new file mode 100644
index 00000000..bfd2fde7
--- /dev/null
+++ b/mitmproxy/web/static/images/favicon.ico
Binary files differ
diff --git a/mitmproxy/web/templates/index.html b/mitmproxy/web/templates/index.html
index 165d7d3d..db9d2ecb 100644
--- a/mitmproxy/web/templates/index.html
+++ b/mitmproxy/web/templates/index.html
@@ -6,10 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/vendor.css"/>
<link rel="stylesheet" href="/static/app.css"/>
+ <link rel="icon" href="/static/images/favicon.ico" type="image/x-icon"/>
<script src="/static/vendor.js"></script>
<script src="/static/app.js"></script>
</head>
<body>
<div id="mitmproxy"></div>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/web/package.json b/web/package.json
index 302803f2..fb2c8c30 100644
--- a/web/package.json
+++ b/web/package.json
@@ -7,6 +7,7 @@
"start": "gulp"
},
"jest": {
+ "testRegex": "__tests__/.*\\Spec.js$",
"testPathDirs": [
"<rootDir>/src/js"
],
diff --git a/web/src/images/favicon.ico b/web/src/images/favicon.ico
new file mode 100644
index 00000000..bfd2fde7
--- /dev/null
+++ b/web/src/images/favicon.ico
Binary files differ
diff --git a/web/src/js/__tests__/ducks/flowView.js b/web/src/js/__tests__/ducks/flowViewSpec.js
index d5d9a6d9..d5d9a6d9 100644
--- a/web/src/js/__tests__/ducks/flowView.js
+++ b/web/src/js/__tests__/ducks/flowViewSpec.js
diff --git a/web/src/js/__tests__/ducks/flows.js b/web/src/js/__tests__/ducks/flowsSpec.js
index 2b261cb1..2b261cb1 100644
--- a/web/src/js/__tests__/ducks/flows.js
+++ b/web/src/js/__tests__/ducks/flowsSpec.js
diff --git a/web/src/js/__tests__/ducks/ui.js b/web/src/js/__tests__/ducks/ui/headerSpec.js
index d3242815..8968e636 100644
--- a/web/src/js/__tests__/ducks/ui.js
+++ b/web/src/js/__tests__/ducks/ui/headerSpec.js
@@ -1,10 +1,10 @@
-jest.unmock('../../ducks/ui')
-jest.unmock('../../ducks/flows')
+jest.unmock('../../../ducks/ui/header')
+jest.unmock('../../../ducks/flows')
-import reducer, { setActiveMenu } from '../../ducks/ui'
-import * as flowActions from '../../ducks/flows'
+import reducer, { setActiveMenu } from '../../../ducks/ui/header'
+import * as flowActions from '../../../ducks/flows'
-describe('ui reducer', () => {
+describe('header reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {}).activeMenu).toEqual('Start')
})
diff --git a/web/src/js/__tests__/ducks/utils/list.js b/web/src/js/__tests__/ducks/utils/listSpec.js
index 72d162f2..72d162f2 100644
--- a/web/src/js/__tests__/ducks/utils/list.js
+++ b/web/src/js/__tests__/ducks/utils/listSpec.js
diff --git a/web/src/js/__tests__/ducks/utils/view.js b/web/src/js/__tests__/ducks/utils/viewSpec.js
index f0b147da..af3da173 100644
--- a/web/src/js/__tests__/ducks/utils/view.js
+++ b/web/src/js/__tests__/ducks/utils/viewSpec.js
@@ -66,11 +66,13 @@ describe('view reduce', () => {
it('should update item', () => {
const state = createState([
{ id: 1, val: 1 },
- { id: 2, val: 2 }
+ { id: 2, val: 2 },
+ { id: 3, val: 3 }
])
const result = createState([
{ id: 1, val: 1 },
- { id: 2, val: 3 }
+ { id: 2, val: 3 },
+ { id: 3, val: 3 }
])
expect(reduce(state, view.update({ id: 2, val: 3 }))).toEqual(result)
})
diff --git a/web/src/js/ducks/utils/view.js b/web/src/js/ducks/utils/view.js
index c00f00bd..6bf0a63e 100755
--- a/web/src/js/ducks/utils/view.js
+++ b/web/src/js/ducks/utils/view.js
@@ -54,21 +54,29 @@ export default function reduce(state = defaultState, action) {
}
case UPDATE:
- if (state.indexOf[action.item.id] == null) {
- return
+ let hasOldItem = state.indexOf[action.item.id] !== null && state.indexOf[action.item.id] !== undefined
+ let hasNewItem = action.filter(action.item)
+ if (!hasNewItem && !hasOldItem) {
+ return state
}
- const nextState = {
- ...state,
- ...sortedRemove(state, action.item.id),
+ if (hasNewItem && !hasOldItem) {
+ return {
+ ...state,
+ ...sortedInsert(state, action.item, action.sort)
+ }
}
- if (!action.filter(action.item)) {
- return nextState
+ if (!hasNewItem && hasOldItem) {
+ return {
+ ...state,
+ ...sortedRemove(state, action.item.id)
+ }
}
- return {
- ...nextState,
- ...sortedInsert(nextState, action.item, action.sort)
+ if (hasNewItem && hasOldItem) {
+ return {
+ ...state,
+ ...sortedUpdate(state, action.item, action.sort),
+ }
}
-
case RECEIVE:
{
const data = action.list.filter(action.filter).sort(action.sort)
@@ -110,7 +118,7 @@ export function receive(list, filter = defaultFilter, sort = defaultSort) {
function sortedInsert(state, item, sort) {
const index = sortedIndex(state.data, item, sort)
- const data = [...state.data]
+ const data = [ ...state.data ]
const indexOf = { ...state.indexOf }
data.splice(index, 0, item)
@@ -134,6 +142,28 @@ function sortedRemove(state, id) {
return { data, indexOf }
}
+function sortedUpdate(state, item, sort) {
+ let data = [ ...state.data ]
+ let indexOf = { ...state.indexOf }
+ let index = indexOf[item.id]
+ data[index] = item
+ while (index + 1 < data.length && sort(data[index], data[index + 1]) > 0) {
+ data[index] = data[index + 1]
+ data[index + 1] = item
+ indexOf[item.id] = index + 1
+ indexOf[data[index].id] = index
+ ++index
+ }
+ while (index > 0 && sort(data[index], data[index - 1]) < 0) {
+ data[index] = data[index - 1]
+ data[index - 1] = item
+ indexOf[item.id] = index - 1
+ indexOf[data[index].id] = index
+ --index
+ }
+ return { data, indexOf }
+}
+
function sortedIndex(list, item, sort) {
let low = 0
let high = list.length
diff --git a/web/src/templates/index.html b/web/src/templates/index.html
index 165d7d3d..db9d2ecb 100644
--- a/web/src/templates/index.html
+++ b/web/src/templates/index.html
@@ -6,10 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/vendor.css"/>
<link rel="stylesheet" href="/static/app.css"/>
+ <link rel="icon" href="/static/images/favicon.ico" type="image/x-icon"/>
<script src="/static/vendor.js"></script>
<script src="/static/app.js"></script>
</head>
<body>
<div id="mitmproxy"></div>
</body>
-</html> \ No newline at end of file
+</html>