From 6560b0dcdba72085ce6c53d68a9e01d293936893 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 15 Aug 2017 22:21:08 +0800 Subject: [PATCH] [web] Change the api routing and minor fix. --- mitmproxy/tools/web/app.py | 14 +++++++------- mitmproxy/tools/web/static_viewer.py | 2 +- web/src/js/backends/static.js | 4 +--- web/src/js/flow/utils.js | 9 +-------- web/src/js/utils.js | 18 +++--------------- 5 files changed, 13 insertions(+), 34 deletions(-) diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py index 2a6f6c9e1..52bac8b0f 100644 --- a/mitmproxy/tools/web/app.py +++ b/mitmproxy/tools/web/app.py @@ -466,10 +466,10 @@ class Application(tornado.web.Application): self.master = master handlers = [ (r"/", IndexHandler), - (r"/filter-help", FilterHelp), + (r"/filter-help(?:\.json)?", FilterHelp), (r"/updates", ClientConnection), - (r"/events", Events), - (r"/flows", Flows), + (r"/events(?:\.json)?", Events), + (r"/flows(?:\.json)?", Flows), (r"/flows/dump", DumpFlows), (r"/flows/resume", ResumeFlows), (r"/flows/kill", KillFlows), @@ -479,13 +479,13 @@ class Application(tornado.web.Application): (r"/flows/(?P[0-9a-f\-]+)/duplicate", DuplicateFlow), (r"/flows/(?P[0-9a-f\-]+)/replay", ReplayFlow), (r"/flows/(?P[0-9a-f\-]+)/revert", RevertFlow), - (r"/flows/(?P[0-9a-f\-]+)/(?Prequest|response)/content", FlowContent), + (r"/flows/(?P[0-9a-f\-]+)/(?Prequest|response)/_content", FlowContent), ( - r"/flows/(?P[0-9a-f\-]+)/(?Prequest|response)/content/(?P[0-9a-zA-Z\-\_]+)", + r"/flows/(?P[0-9a-f\-]+)/(?Prequest|response)/content/(?P[0-9a-zA-Z\-\_]+)(?:\.json)?", FlowContentView), - (r"/settings", Settings), + (r"/settings(?:\.json)?", Settings), (r"/clear", ClearAll), - (r"/options", Options), + (r"/options(?:\.json)?", Options), (r"/options/save", SaveOptions) ] settings = dict( diff --git a/mitmproxy/tools/web/static_viewer.py b/mitmproxy/tools/web/static_viewer.py index 23228b3b4..01ecc3bbc 100644 --- a/mitmproxy/tools/web/static_viewer.py +++ b/mitmproxy/tools/web/static_viewer.py @@ -54,7 +54,7 @@ class StaticViewer: path = os.path.join(self.path, 'flows', f.id, m) if not os.path.exists(path): os.makedirs(path) - with open(os.path.join(path, 'content.json'), 'wb') as content_file: + with open(os.path.join(path, '_content'), 'wb') as content_file: content_file.write(message.raw_content) # content_view diff --git a/web/src/js/backends/static.js b/web/src/js/backends/static.js index 6657fecf1..7e87a5eda 100644 --- a/web/src/js/backends/static.js +++ b/web/src/js/backends/static.js @@ -11,10 +11,8 @@ export default class StaticBackend { } onOpen() { - this.fetchData("settings") this.fetchData("flows") - this.fetchData("events") - this.fetchData("options") + // this.fetchData("events") # TODO: Add events log to static viewer. } fetchData(resource) { diff --git a/web/src/js/flow/utils.js b/web/src/js/flow/utils.js index cb37822a4..9915a639a 100644 --- a/web/src/js/flow/utils.js +++ b/web/src/js/flow/utils.js @@ -49,14 +49,7 @@ export var MessageUtils = { } else if (message === flow.response) { message = "response"; } - if (global.MITMWEB_STATIC) { - let url = view ? - `/flows/${flow.id}/${message}/content/${view}.json` : - `/flows/${flow.id}/${message}/content.json` - return url; - } else { - return `/flows/${flow.id}/${message}/content` + (view ? `/${view}` : ''); - } + return `/flows/${flow.id}/${message}/` + (view ? `content/${view}.json` : '_content'); } }; diff --git a/web/src/js/utils.js b/web/src/js/utils.js index 505f74df9..3aeba1b19 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -81,27 +81,15 @@ function getCookie(name) { } const xsrf = `_xsrf=${getCookie("_xsrf")}`; - export function fetchApi(url, options={}) { - if (global.MITMWEB_STATIC) { - let path = url.split('/'), - filename = path.pop() - filename += '.json' - path.push(filename) - let new_url = path.join('/') - return _fetchApi(new_url, options) - } else { - return _fetchApi(url, options) - } -} - -function _fetchApi(url, options={}) { if (options.method && options.method !== "GET") { if (url.indexOf("?") === -1) { url += "?" + xsrf; } else { url += "&" + xsrf; } + } else { + url += '.json' } return fetch(url, { @@ -110,7 +98,7 @@ function _fetchApi(url, options={}) { }); } -fetchApi.put = (url, json, options) => _fetchApi( +fetchApi.put = (url, json, options) => fetchApi( url, { method: "PUT",